Category: Issues and Solutions

PHP imagecreatefromjpeg() Premature end of JPEG file issue

You can check the solution below to resolve this issue related to PHP GD Library function imagecreatefromjpeg():


You can set default value of gd.jpeg_ignore_warning=1 in php.ini
You can set it like this ini_set('gd.jpeg_ignore_warning', true); in your PHP script before calling imagecreatefromjpeg()

After implementing any of the above, GD Library will ignore the error where it use to fail and imagecreatefromjpeg() will return an image resource identifier.

Note: In PHP 7.1.0 the default value of gd.jpeg_ignore_warning has been changed from 0 to 1.