New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
altrim opened this Issue Jul 14, 2013 · 13 comments

Comments

Projects
None yet
7 participants
@altrim
Copy link

altrim commented Jul 14, 2013

I am using this package with laravel and for some files that I am trying to resize it happens randomly I get this error:

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

Stack Frame

/Applications/MAMP/htdocs/laravelweb/vendor/intervention/image/src/Intervention/Image/Image.php

       case IMG_PNG:
       case 3:
       $this->resource = imagecreatefrompng($path);
       break;

       case IMG_JPG:
       case 2:
       $this->resource = imagecreatefromjpeg($path);
       break;
@olivervogel

This comment has been minimized.

Copy link
Member

olivervogel commented Jul 14, 2013

Please send me a link to one of these files, so I can fix it.

@altrim

This comment has been minimized.

Copy link
Author

altrim commented Jul 14, 2013

I am testing with local personal images, I don't have link to an image that might help. It has something to do with damaged JPEG files. After I optimize the image with ImageOptim the error goes away.

@olivervogel

This comment has been minimized.

Copy link
Member

olivervogel commented Jul 15, 2013

I can't reproduce this error without such a damaged JPEG file. But I think you can suppress this error output with ini_set('gd.jpeg_ignore_warning', true);

@altrim

This comment has been minimized.

Copy link
Author

altrim commented Jul 15, 2013

Hey I found a damaged image, you can take a look at this link for the image http://www.gobiernohuejotzingo.gob.mx/img/noticias/123/123-7EJU0GUFYS.JPG

@olivervogel

This comment has been minimized.

Copy link
Member

olivervogel commented Jul 15, 2013

Thank you for the test image. I did a little research and it seems that GD can't handle this kind of damaged images.

However, I managed to read and resize your image, if the error warnings are suppressed with the following ini setting:

ini_set('gd.jpeg_ignore_warning', true);

@altrim

This comment has been minimized.

Copy link
Author

altrim commented Jul 15, 2013

Ok so will this be added in the library or I should add it in the function where I am resizing the image ?

@olivervogel

This comment has been minimized.

Copy link
Member

olivervogel commented Jul 15, 2013

I think it's better to add this locally, when problems occur.

@newtonianb

This comment has been minimized.

Copy link

newtonianb commented Oct 21, 2014

I keep getting this error imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes before marker 0xd9 #250 even with ini_set('gd.jpeg_ignore_warning', true);

The command I'm running is trigerred through a laravel command.

I tried placing this ini_set('gd.jpeg_ignore_warning', true); in

  • index.php
  • artisan
  • Decoder.php (intervention)

But I always keep getting that error for that one image. This image does open normally though. Is there another kind of ignore warning flag I should be using?

@barryvdh

This comment has been minimized.

Copy link
Contributor

barryvdh commented Jun 22, 2016

Also see this thread: owncloud/core#21950

Perhaps we should add that here also?

@barryvdh

This comment has been minimized.

Copy link
Contributor

barryvdh commented Jun 22, 2016

Also, with Laravel, I think the problem is that instead of warnings, that options generates notices. And notices are still triggering the error handler. So you might want to change your error reporting settings to ignore notices.

@stueynet

This comment has been minimized.

Copy link

stueynet commented Jan 3, 2017

Solved this with ini_set("gd.jpeg_ignore_warning", 1) in my constructor.

@hassanamirkhan

This comment has been minimized.

Copy link

hassanamirkhan commented Apr 5, 2017

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

@jaystream

This comment has been minimized.

Copy link

jaystream commented Aug 24, 2017

Thank you. It solve my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment