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():

Solution:

You can set default value of gd.jpeg_ignore_warning=1 in php.ini
OR
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.

Reference: https://www.facebook.com/notes/php-tutors/php-gd-library-imagecreatefromjpeg-premature-end-of-jpeg-file-issue/721592434694661