PHP exif_read_data Illegal IFD size

前端 未结 5 1825
面向向阳花
面向向阳花 2021-02-18 22:45

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 Rotat

相关标签:
5条回答
  • 2021-02-18 23:33

    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)

    0 讨论(0)
  • 2021-02-18 23:34

    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){
            ...
         }
    
    0 讨论(0)
  • 2021-02-18 23:40

    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.

    0 讨论(0)
  • 2021-02-18 23:45

    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);
    
    0 讨论(0)
  • 2021-02-18 23:47

    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
      }
    
    0 讨论(0)
提交回复
热议问题