19

I'm working on an application where I fix orientation (if it is present) of jpeg files downloaded from an AWS bucket.

Here you can verify that this image has exif Rotation section.

I download the image with

file_put_contents('/local/path/to/file', file_get_contents('/path/to/url/image'));

And after I try to fix orientation through the Gregwar Image library.

Image::open($path)->fixOrientation()->save($dest, $type, $quality);

I tried with several images and I always receive the message

Warning: exif_read_data('/local/path/to/file'): Illegal IFD size

I thought that was a problem related with how I retrieve the images, but I tried also with cUrl and fopen with the same result.

Someone has some advices?

stuzzo
  • 1,056
  • 1
  • 15
  • 36

5 Answers5

7

You can use a "@" before to ignore warnings: @Image::open($path)->fixOrientation()->save($dest, $type, $quality);

That is a lot of people complaining about this over the internet. Probably some exif data with error. If you operation is working the way you want, just document it and move on.

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • 4
    Hi, thank you for the advice, but my problem isn't the warning (that the library wrap), but why I'm unable to check exif data. At this time, I'm not able to fix orientation of any image and this is frustrating. – stuzzo May 20 '16 at 17:36
  • Try with this: `->useFallback(false)`: https://github.com/Gregwar/Image/issues/96 – Felippe Duarte May 20 '16 at 17:40
  • Hi @auco, unfortunately no. When I got the warning, I discarded image to fix orientation. – stuzzo Jan 10 '18 at 16:28
4

PHP 5.6.2x is having a bug with its EXIF capability (see bug #72914 as well as #72819 for further info). Attempting to read EXIF data will result in one of the described errors (Illegal IFD size, IFD bad data, other).

At present (2016-11-21) there is no fix available for the 5.6 branch. There is some testing going on in branch 7.

Implement a local fix by testing for the function throwing IFD errors, and when confirmed assume EXIF to be unavailable for the duration of the script.

(You can patch that into the loader if you wish, and 'overload' the functions to return default false/0/null instead to indicate breakage)

1

I've also encountered this problem using exif_get_data. I can handle images on my localhost (PHP v5.4.15) but on my web host (PHP v5.6.22) the error 'illegal IFD size' even though I'd tried the "@" ignore warning method. I found that on the web host (whether because of different version or installation), exif_get_data was actually throwing an exception rather than issuing a warning. I'm using the exif data to reorientate the picture if it's been rotated, so if the exif data is faulty or not present I just ignore it and do nothing, here's the code snippet:

     try {
        $exif = exif_read_data($filePath);
     }
     catch (Exception $exp) {
        $exif = false;
     }
     if ($exif){
        ...
     }
Arfon
  • 69
  • 5
1

In production environment, the best is still to hide warnings!

So I changed he error reporting to ERRORS only with the following line in begining of my script :

error_reporting(E_ERROR);
Meloman
  • 3,558
  • 3
  • 41
  • 51
0

you can catch an error with set_error_handler

set_error_handler(function() {
  throw new Exception();
 }, E_WARNING);

  try{
     $exifData = exif_read_data($filePath);
  } catch (Exception $e) {
     $exifData = false;
  } finally {
     restore_error_handler();
  }

  if(!$exifData) {
     // do something
  }