Igor's Blog

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

, ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

Binding extra variables with PHP PDO returns no results

New Nintendo 3DS XL, R4i SDHC RTS Lite and DSDoom

Older versions of JD-GUI crashing on macOS Sierra

How does Seeed Fusion stack up as a low budget PCB fab

Where to find the last item (Robbie's lost lyrics) in GravityFalls Lake level

Detecting print requests to print contents of a DIV with JavaScript

Using Google DFP with AdSense on responsive pages

How to change the email subject line in Gmail

Force PHP GD library to load JPEG images that have invalid data

How to uninstall Samsung Smart Switch from your Mac

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again