How to apply ImageMagick effect (selective blur) to all WordPress uploaded images automatically ? I have Imagick installed

不羁岁月 提交于 2020-07-23 06:46:23

问题


I don't really know how to apply php code to WordPress manually. I have found some script but don't know where and how to put them.

public Imagick::selectiveBlurImage ( float $radius , float $sigma , float $threshold [, int $channel = Imagick::CHANNEL_DEFAULT ] ) : bool

<?php
function selectiveBlurImage($imagePath, $radius, $sigma, $threshold, $channel) {
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->selectiveBlurImage($radius, $sigma, $threshold, $channel);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}

?>

Source Imagick::selectiveBlurImage

And want to add it as this filter will act before finally uploading image. Found similar function at wp-admin/includes/file.php

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );

function custom_upload_filter( $file ){
    $file['name'] = 'wordpress-is-awesome-' . $file['name'];
    return $file;
}

Source 1st Page & 2nd Page

If there isn't any way to pre-apply filter effect then auto-apply effect after upload is welcome.

If there there is any WordPress Plug-in available to do that?

The effect will change original photo to this photo

Effect Source Fred's ImageMagick Scripts with effect arguments: -b 4 -t 10 -e none -q 0

There is a similar question ,but i am unaware of the file directory and process to add those code. It has some resize issue which in my case isn't. I want to apply this filter to any picture uploaded.

来源:https://stackoverflow.com/questions/62703469/how-to-apply-imagemagick-effect-selective-blur-to-all-wordpress-uploaded-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!