views:

74

answers:

2

Hi all, I've been getting this warning when some people upload images to our site :

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/sherifo/private/includes/snapsutils.php on line 220

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/tmp/phpiw4MFk' is not a valid JPEG file in /home/pathremoved.php on line 220

Warning: imagesx(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 222

Warning: imagesy(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 223

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/pathremoved.php on line 240

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 242

This only happens with certain images, which when opened in any program are ok, it even uploads to the version of the site I have on localhost with no problems...I googled a bit but found nothing conclusive...

I've put the problematic image here (it's 2mb) : http://www.buzzarab.com/bug/2.jpg

note php upload_max size is 5M and post_max_size is 5M. This is not an upload or memory issue. I've tested with 4M images without problems.

any help appreciated.

A: 

This image cause a never-ending request to the server in Firefox (3.6.10). Firefox says it contains errors.

ilcartolaio
I just tried it on firefox mac (3.5.11) and it opens fine. Also chrome, IE8 no issues...
Sherif Buzz
Yes, I can view the image, but loading never ends and if I try to stop it, the above error appears.
ilcartolaio
A: 

After a little digging around on Google I found this bug report. It seems that the GD library is less tolerant of buggy JPEG files than other programs. The solution suggested was to set GD to ignore JPEG error's before processing the image, like this:

ini_set("gd.jpeg_ignore_warning", 1);

Hopefully that will work for you. One other potential problem you may run into is to do with memory. It seems that GD holds all images in memory as bitmaps once they've been opened. This means that a 5MB image can actually consume more memory than a single PHP thread is allowed, resulting in a fatal error. I had this problem with some image uploads and had to reduce the maximum file size I allowed to get around the problem.

Good luck and hope that helps.

Jeremy
thanks for the hint, i put that in but unfortunately didn't fix the issue.
Sherif Buzz
Jeremy
There was also this comment in the manual: "If you get this error: "Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error" then check the JPEG files. If they are saved in CMYK format (instead of RGB) then GD will fail to load them (tested with GD 2.0.12)". Finally, there were comments about images shot with certain cameras which wrote extra information into the JPEG headers causing problems. Hopefully one of these ideas will solve your problem.
Jeremy