Level 11
May 10, 2024
2
Level 2
Intervention\Image : Image source not readable
Hello, I'm experiencing a problem (in some cases, but not always...). I can't reproduce the problem so I need help.
Here is the function
public function storeMedia(Request $request)
{
$path = public_path('uploads');
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$image = $request->file('file');
$input['image_name'] = Str::lower(Str::uuid()) . '.' . $image->getClientOriginalExtension();
$height = 1200;
$width = 1200;
$img = \Intervention\Image\Facades\Image::make($image->path()); // THIS LINE SOMETIMES THROWS AN EXCEPTION
$img->height() > $img->width() ? $width = null : $height = null;
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
$img->orientate();
$img->save($path . '/' . $input['image_name']);
return $input['image_name'];
}
The exception is :
(Intervention\Image\Exception\NotReadableException(code: 0): Image source not readable
In 95% of cases everything works fine, so I don't think it's a path or permission problem.
Thansk!
Please or to participate in this conversation.