我创建了一个上传图片及其标题、描述等内容的应用程序。但是,我在一些图片上传时遇到了问题,它返回了一个错误("Image source not readable"),如下所示:
以下是我的代码:
$image = $request->file('image');
// $image = Input::file('image'); // already tried this one still same problem
$orginal_filename = $image->getClientOriginalName();
$ext = $image->getClientOriginalExtension();
$fileName = md5(microtime() . $orginal_filename) . '.' . $ext;
$img = Image::make($image->getRealPath());
$img->stream();
$img->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('storage_dir')->put($dir . $fileName, $img, 'public');
已经尝试了以下解决方案:
- 更改为Input :: file('file')
- 检查请求Content-Type是否为multipart / form-data (请求已经具有multipart / form-data Content-Type)
- 将Intervention Image驱动程序从"gd"更改为"imagick"
但仍然出现“图像源不可读取”错误。
注意:错误仅发生在某些图像中。(我还尝试将产生错误的图像移动到另一个目录,但仍然出现错误)。
非常感谢您的帮助!