PHP-有没有更好/更智能的模糊图像方法


PHP - Is there better/smarter way for blur image?

我使用高斯模糊。 1行

imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);

没有提供所需的模糊强度。所以我需要用30次。这是一种不专业的方式,当页面上有很多图像时,它会大大增加页面加载时间。那么,有没有更好/更智能的图像模糊方法呢?

  $image = imagecreatefromjpeg("caski_m.jpg");
  imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
  header("content-type: image/jpeg");
  imagepng($image);
  imagedestroy($image);

如果您正在搜索更简洁、更优雅的解决方案,那么:

  1. php安装ImageMagick扩展
  2. 使用php exec命令调用ImageMagick convert运算符:

架构:exec("convert <your_image_name> -blur <blur_level> <your_blured_image_name> ");
您可以灵活调整模糊级别
示例:exec("convert '$image' -blur 0x8 'blur_' . $image");
但不要忘记指定可访问的图像路径
要获得更多选项,请查看以下内容:imagick_blur_guide