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

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Coherence and weblogic.xml in different types of J2EE web app deployments

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 1 - introduction and case disassembly

jPhotoFrame updated to version 0.3.1 with an image rotation correction utility

iOS 11 pre-GM mini review before it gets revealed next week

Why you should never use Java enums as keys with Oracle Coherence caches

Hacking the VideoPak 7inch promotional brochure to work as a digital photo frame

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity