php - 使用干预将图像转换为灰度
问题描述
我正在尝试将我的图像转换为灰度,然后在Laravel中下载它,但每次我都收到此错误
文件“”不存在
不知道为什么它在这里给出这个错误是我的代码。
$file = public_path() . "/large/s/" . $sheet[0]->sheet_f_id . '-s.jpg';
$image = Image::make($file);
$grayScale = $image->greyscale();
return Response::download($grayScale);
当我转储$file
变量时,我得到了类似这样的响应。
“D:\xampp\htdocs\wikistaging\public/large/s/03-02-05-025-s.jpg”
但它仍然给了我山姆错误,为什么会发生这种情况。任何帮助都会很棒。
解决方案
如果要下载,则首先必须保存创建的文件并需要提供下载路径。这是工作示例
$img_name=$sheet[0]->sheet_f_id . '-s.jpg';
$destination_path=public_path() . "/large/s/";
$file = $destination_path.$img_name;
$image = Image::make($file);
$image->greyscale()->save($destination_path.'gray-'.$img_name);
return Response::download($destination_path.'gray_'.$img_name);
如果您不想保留可以删除的文件,请将最后一行替换为以下行。
return Response::download($destination_path.'gray_'.$img_name)->deleteFileAfterSend(true);
希望它对你有用。
推荐阅读
- ssh - 如何在子域上设置 Mercurial 服务器?
- node.js - 如何分配承诺然后响应外部变量?
- javascript - NullInjectorError:没有 MatBottomSheetRef 的提供者
- javascript - 按字符串数组过滤javascript数组
- java - 使用 Android-Camera2 API 访问 USB 摄像头
- python - 如何从 numpy 数组创建 .fits 文件
- css - 如何在聊天室中将我的聊天条目与右侧对齐?
- php - 在 WooCommerce 快速订单预览中显示自定义字段
- flutter - 在 null 上调用了 getter 'classification'
- c# - 如何一次替换所有列表框项目