Search code examples
laravel-4intervention

imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file


I'm using intervention/image module with laravel 4.2 , to upload images i'm using this code :

if (Input::hasFile('image'))
        {
            $file = Input::file('image');
            $file->move('uploads/2/', $file->getClientOriginalName());
            $image = Image::make(sprintf('uploads/2/%s', $file->getClientOriginalName()))->resize(120, 120)->save();
            return 'yes';
        }

With some images it works , with some images it produces this error :

imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file 

switch ($info[2]) {
            case IMAGETYPE_PNG:
                $core = imagecreatefrompng($path);
                $this->gdResourceToTruecolor($core);
                break;

            case IMAGETYPE_JPEG:
                $core = imagecreatefromjpeg($path);
                $this->gdResourceToTruecolor($core);
                break;

Solution

  • This is because you upload corrupted images and GD can't handle that kind of images. Please check it in this issue .

    Try to suppress this error like this.

    ini_set('gd.jpeg_ignore_warning', true);
    

    Hope it will be useful for you.