Fix to the “Corrupt JPEG data” error

Sometimes images get corrupted, and can not be uploaded correctly using php. Where I work this happened once in a while, and I did not know how to fix it. When a user sent me an image by email, I could at least recognize the error – It was “Corrupt JPEG data: XXXX extraneous bytes before marker XxXX”.

Having known this I could google it, but the solution was not easy to find because the problem was not in PHP, but in the image. Anyway, the fix was simple. Just ignore the error by adding this to the code:

ini_set(“gd.jpeg_ignore_warning”, true);

An other solution is to save the file again with a program like Photoshop(that can open these rare corrupted jpegs) – then it is saved correctly as an uncorrupted jpeg file and can be uploaded.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: