在laravel中使用干预库进行图像模糊效果

时间:2017-10-02 08:16:28

标签: php laravel laravel-5 intervention

我正在尝试为我的图片添加模糊效果。我正在使用laravel 5.2和Intervention Image 2 library。这是blur method。我在我的代码中做了完全相同但它没有做任何事情(图像保持不变)。这是代码: 在我存储输入数据和图像的控制器中,我调用makeBlur()辅助函数。图像路径存储在$path_preview

控制器:

// some code ...
makeBlur($path_preview); // <-- looks like /uplodas/image.jpg
// some code ....
$model->path_preview = $path_preview;
$model->save();

这是辅助函数:

// $image is string (stores the path of file)
function makeBlur($image){
  $path = public_path() . $image; // get image path add public/ in front of it
  $blurredImg = \Image::make($path);
  $blurredImg->blur(45);
}

没有错误,没有任何反应。也许我不知道它是如何工作的

1 个答案:

答案 0 :(得分:0)

应用模糊后保存图像

$blurredImg->blur(45)->save($image);