Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4.2 throws NotReadableException "Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files."

After checked about 20 solutions I gave up and need help. I've got 2 JPG files. Both have proper mime, they are not too big for upload_max_filesize, names are ok, path is ok. Every solution was about one of those issues.

My problem is when I run script on first image it is ok, no error, object is created:

$image1 = Image::make(public_path()."/uploads/goodimage.jpg");

See example: https://app.esticrm.pl/uploads/goodimage.jpg

When I run it on other picture I'm getting error:

$image2 = Image::make(public_path()."/uploads/badimage.jpg");

See example: https://app.esticrm.pl/uploads/badimage.jpg

Error message:

Intervention \ Image \ Exception \ NotReadableException Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

Same situation on Windows and Linux. Files are opening on every graphic program and browser I've checked. Those problems has started after PHP upgrade from 5.5.x to 5.6.35. Was fine before.

like image 571
wesol3d Avatar asked Aug 31 '25 02:08

wesol3d


2 Answers

Ok, I found solution:

$image2 = Image::make(file_get_contents(public_path()."/uploads/badimage.jpg"));

Works also on file object from form:

$image2 = Image::make(file_get_contents(Input::file('upload_file'));
like image 135
wesol3d Avatar answered Sep 02 '25 17:09

wesol3d


I had the same problem and my way of solving was the next. I had to change the size that nginx allowed the user to upload in /etc/nginx.conf, like this:

 http {
    client_max_body_size 100M;
 }

And I had to change also my php.ini, to increase the size of the files uploaded and the total size:

upload_max_filesize = 4M
post_max_size = 16M

I hope helps someone

like image 25
Evan Avatar answered Sep 02 '25 16:09

Evan