JPEG image problem with PHP GD

I wrote a PHP script based on imagecopyresampled() to resize images coming from mobile phones. Some phone models seem to produce corrupt JPEG files. As on calling imagecreatefromjpeg() a message gets produced looking like: \”Corrupt JPEG data: 164 extraneous bytes before marker 0xd9\”.

Imagemagick handles such problems in some – to me unknown – way and resizes the image properly, regardless of the problem pointed out. But there is currently only GD available and with that few lines of code I get a black resized thumbnail.

The message pointed out above gets printed out when calling imagecreatefromjpeg(). A random thought was to rewrite a function from scratch in PHP that creates a valid image resource [1] in spite of the corrupt JPEG format. But as we have 23p.m. now, I am just too tired now 😉 So I am stuck. A corrupt image can be found here [2].

[1] http://lxr.php.net/source/php-src/ext/gd/libgd/gd_jpeg.c#238
[2] http://circle.ch/blog/media/bild015.jpg

Update: Problem-walk-around, as I got imagemagick support on the server 😉

Leave a Reply