【问题标题】:Converting images to greyscale using intervention使用干预将图像转换为灰度
【发布时间】:2018-05-26 01:45:28
【问题描述】:

我正在尝试将我的图像转换为灰度,然后在 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”

但它仍然给我一个山姆错误,为什么会发生这种情况。任何帮助都会很棒。

【问题讨论】:

    标签: php laravel-5 grayscale intervention


    【解决方案1】:

    如果你想下载,那么首先你必须保存创建的文件并需要提供下载路径。这是工作示例

    $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);
    

    希望它对你有用。

    【讨论】:

    • 先生,它对我不起作用,因为它给了我这个错误。 The file "D:\xampp\htdocs\wikistaging\public/large/s/gray_03-02-05-029-s.jpg" does not exist 现在
    • @MohsinAbbas 代码已检查并在我这边工作,请检查您使用的路径是否正确。
    • 先生,您说得对,代码正在您这边工作,但现在它给了我这个错误。 Image source not readable
    • 请问先生,您能告诉我这是怎么回事吗?灰色文件夹也没有制作,但文件以大/秒的形式保存,名称为 gray-filename
    • 灰色文件夹不会创建我们添加灰色只是为了区分,尝试打印这个 $file 是否获得完整路径。
    【解决方案2】:

    您必须在调用 greyscale() 后保存您的图像。 你可以试试:

    $filePath = public_path() . "/large/s/" . $sheet[0]->sheet_f_id . '-s-test.jpg';
    $image->greyscale();
    $image->save($filePath);
    

    【讨论】:

      猜你喜欢
      • 2010-11-20
      • 2021-06-06
      • 2018-12-19
      • 2018-08-15
      • 1970-01-01
      相关资源
      最近更新 更多