Laravel 5.6 图像干预库:'Image Source Not Readable'
Laravel 5.6 Image Intervention Library: 'Image Source Not Readable'
我正在使用 Image Intervention Library 调整图像大小,我已完成以下步骤:
1- 安装库: composer require intervention/image
2- 代码中的用法:
$file = $request->file('logo');
$destinationPath = 'db_images/public/';
$filename = $file->getClientOriginalName();
$extension = explode(".",$filename)[1];
$name = md5(microtime()).".".$extension;
$image_path = $destinationPath.$name;
$img = Image::make($filename)->resize(254,
179)->save($image_path);
$file->move($destinationPath,$img);
问题是:
当我尝试使用上面的代码上传文件时,这将 return 我 'Image Source is not readable'.
请帮助我解决这个问题。谢谢
您只将文件名传递给 make
方法,您必须传递文件对象或文件路径:
文件:
$img = Image::make($file)->resize(254, 179)->save($image_path);
路径:
$img = Image::make($file->getRealPath())->resize(254, 179)->save($image_path);
我正在使用 Image Intervention Library 调整图像大小,我已完成以下步骤:
1- 安装库: composer require intervention/image
2- 代码中的用法:
$file = $request->file('logo');
$destinationPath = 'db_images/public/';
$filename = $file->getClientOriginalName();
$extension = explode(".",$filename)[1];
$name = md5(microtime()).".".$extension;
$image_path = $destinationPath.$name;
$img = Image::make($filename)->resize(254, 179)->save($image_path);
$file->move($destinationPath,$img);
问题是: 当我尝试使用上面的代码上传文件时,这将 return 我 'Image Source is not readable'.
请帮助我解决这个问题。谢谢
您只将文件名传递给 make
方法,您必须传递文件对象或文件路径:
文件:
$img = Image::make($file)->resize(254, 179)->save($image_path);
路径:
$img = Image::make($file->getRealPath())->resize(254, 179)->save($image_path);