3

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!

Edwin Bermejo
  • 432
  • 3
  • 5
  • 17
  • are you using HTML form to upload image ? – Muhammad Sipra Jan 30 '19 at 06:49
  • Try first to see what the type of the Images, to can use this command to see what is the format: identify "IMG PATH" – Ali Al-Estarbadee Jan 30 '19 at 07:12
  • I'm using an HTML form, append it into a FormData then sent a post request @Muhammad Sipra – Edwin Bermejo Jan 30 '19 at 07:25
  • @Ali Mohammed, sorry i don't get it, can u please elaborate? – Edwin Bermejo Jan 30 '19 at 07:38
  • @EdwinBermejo, please check your input parameters specifically your image parameter by printing your parameters on the server side. In this way, we would be able to see that what kind of data you are receiving from your form – Muhammad Sipra Jan 30 '19 at 07:44
  • @EdwinBermejo, for example, we need to check if the image is supported by imagick, because some formate of images is not supported like HEIC/HEIF format, you can check what is the format of the image from the command line: identify "IMG PATH" – Ali Al-Estarbadee Jan 30 '19 at 07:58
  • @Ali Mohammed already tried checking the image format, it is a JPEG. Already looked in intervention image docs also and now know that JPEG is both supported by GD and imagick driver but still have same issue. – Edwin Bermejo Jan 30 '19 at 13:59
  • Here' an update, i tried showing the image realpath ($img->getRealPath()) and find out that the image that i'm having the problem is not saving to xampp's tmp directory but the rest of the images that worked is saved first into the tmp directory then saved into the desired directory. Maybe someone knows the reason why, Thanks. – Edwin Bermejo Jan 31 '19 at 02:30

5 Answers5

5

You can try running my code

if ($request->file('photo')->isValid()) {
        $avatar = $request->file('photo');

        $filename = time() . '.' . $avatar->getClientOriginalExtension();

        Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename) );

    }

/uploads/avatars/ is my directory

5

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)

RSorensen
  • 141
  • 2
  • 4
2

Sorry for bothering guys! It seemed that it was all my fault not realizing php post_max_size and php upload_max_file_size. Since i was trying to upload an image larger than 8MB i only increased the post_max_size > than the current image file size, but not the upload_max_file_size coz i only increased it by 2 (stated: 4MB).

Thanks btw for the help and suggestions!

Edwin Bermejo
  • 432
  • 3
  • 5
  • 17
  • For some reason, this solved my problem. The `upload_max_file_size` of my server is only 2MB, while I'm uploading a 4MB document. What a deceiving error message that is! – PinoyStackOverflower Aug 27 '22 at 13:48
0

Replace

$resize = Image::make('storage/app/public/'.$user->image)->resize(300,300);

with

$resize = Image::make(storage_path('app/public/'.$user->image))->resize(300,300);

Give storage full path will solve the problem.

Mohnish
  • 1,010
  • 1
  • 12
  • 20
0

If you got this error on your server, you need to be sure you pushed the all images to server. You are facing this error because of server could not find or read to image/images.

-> Be sure image/images uploaded
-> Make readable to image/images.

Enver
  • 542
  • 5
  • 7