Laravel 5.7 + Intervention Image : Image source not readable

Edwin Bermejo picture Edwin Bermejo · Jan 30, 2019 · Viewed 9.6k times · Source

I've create an app that upload image along with title, description & etc. However, i'm having a problem in some of the images to upload, it returns an error ("Image source not readable") as shown below:

enter image description here

Here's my Code:

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

Already tried following solutions:

  • Change to Input::file('file')
  • Check if Request Content-Type has multipart/form-data (Request already has multipart/form-data Content-Type)
  • Change Intervention Image driver from "gd" to "imagick"

but still have the "Image source not readable" error.

Note: Error only occurs in some images. (I've also tried moving the image(w/c produced the errors) into another directory but still error occurs).

Thank you so much for the help!

Answer

RSorensen picture RSorensen · Aug 8, 2019

If the problem occours in a Laravel 5.7 project, and you store your pictures in the storage folder, it might solve the problem to enter this into the terminal:

php artisan storage:link

(The problem occurs if you have cloned the project from github og bitbucket)