Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP imagecreatefromstring(): gd-jpeg, libjpeg: recoverable error

Tags:

php

gd

I'm trying to load an image from an external site over which I have no control.

Most of the time it works fine (hundreds of images tested so far).

It's now giving me this error for one particular image:

imagecreatefromstring(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: premature end of data segment

from this line:

$im = @imagecreatefromstring( $imageString );

The advice I'd read so far suggests adding:

ini_set("gd.jpeg_ignore_warning", true);

but that's had no effect and I'm still getting the error. I'm doing the ini_set just before the call. Is that relevant?

I'm really stuck on how to ignore this error and carry on.

like image 626
Ted Avatar asked Apr 08 '11 08:04

Ted


2 Answers

The problem was due to my error handling. I'd set up an error handler so my call to

$im = @imagecreatefromstring( $imageString );

wasn't suppressing errors.

By modifying my error handler with:

   if (error_reporting() === 0)
   {
        // This copes with @ being used to suppress errors
        // continue script execution, skipping standard PHP error handler
        return false;
   }

I can now correctly suppress selected errors.

I found the info here: http://anvilstudios.co.za/blog/php/how-to-ignore-errors-in-a-custom-php-error-handler/

like image 136
Ted Avatar answered Oct 16 '22 23:10

Ted


this can be solve with:

ini_set ('gd.jpeg_ignore_warning', 1);
like image 2
حسین عبایی Avatar answered Oct 16 '22 21:10

حسین عبایی