Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

While updating code my my travelblog.ws project I came across an issue where I was not able to upload certain JPEG files to the blog and have them automatically scaled down for thumbnail generation. The files opened fine on my Mac but PHP would not load them.

This was the kind of error I was getting...
 PHP Error
PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Invalid SOS parameters for sequential JPEG
PHP Warning: imagecreatefromjpeg(): 'uploads/58a0ca1e227b5_20170210_170151.jpg' is not a valid JPEG file in UploadHandler.php on line 562


I wasn't exactly sure what that meant but since these files were loadable on my Mac there had to be a way to get them loaded via GD too, and I found it. There was a runtime configuration documentation page for the PHP GD library that described an INI parameter that could be set that would make GD ignore warnings while loading JPEGs. After setting the gd.jpeg_ignore_warning parameter to 1 I was able to load these seemingly 'corrupted' JPEGs.

Here's the code I used to set the parameter. I placed this right before any of the calls to the GD functions.
 PHP
ini_set('gd.jpeg_ignore_warning', 1);




Interestingly from version 7.1 of PHP, the documentation says this - The default of gd.jpeg_ignore_warning has been changed from 0 to 1.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.