PHP / (bad) data / exif warnings what to do?

I am writing a small script that collects a pair of exif values ​​from images ... namely the creation date, make and model.

I notice (especially with the image sent by the mail application by default) that the exif data has been changed, which is a known issue (the mail application compresses the images before sending them, even if "full size" is selected). The values ​​I'm looking for seem to exist, although I get PHP warnings by accessing them. Actually no problems arise, but the warning obviously does not work for me.

Calling ini_set ('display_errors', 0) hides the warnings, but it seems messy to me. Is there a way to ignore this warning, in this script, is a little better for this script?

My initial thought was to wrap everything in try / catch, but the warning is still showing on the main page.

I just use the standard exif_read_data () function, I think the external library will be a little more than what I need.

PHP:

  if ($ _ GET ['i']) {
   $ input = strtolower ($ _ GET ['i']. ".jpg");
   if (file_exists ($ input)) {
     $ exif = exif_read_data ($ input);
     foreach ($ exif as $ key => $ value) {
       if (! in_array ($ key, Array ("DateTime", "Make", "Model"))) {
         unset ($ exif [$ key]);
       }
     }
     ksort ($ exif);
     print_r ($ exif);
   }
 }

Attention:

Warning: exif_read_data(trailmarker.jpg) [exif_read_data]: Illegal IFD size: x00C4 + 2 + x3239*12 = x25B70 > x2B74 in C:\xampp\htdocs\exif\dumpfolder\exif.php on line 5

+6
php exif
source share
2 answers

You can use @operator to hide the warning without using display_errors, i.e.

 $exif = @exif_read_data(..); 

This is better than setting display_errors , as it disables warnings / errors for the exif read-only function and does not hide other possible errors in your code.

+25
source share

Despite the fact that this is an old topic, for me it came out of nowhere with the new php 7.2: Error # 75785 Many errors from exif_read_data

I agree with @maraspin, since any error for any reason and does not deal with it, means poor performance (time, functions).

My goal : get the "DateTimeOriginal" of the uploaded image (not just the create_date file from the tmp file - DateTime).

1. Normal use of exif_read_data:

 $exif = exif_read_data(tmp/phpTBAlvX); or $exif = exif_read_data($file->tempName, 'ANY_TAG'); or $exif = exif_read_data($file->tempName, 'IFD0'); or $exif = exif_read_data($file->tempName, 'EXIF'); 

PHP Warning - yii \ base \ ErrorException exif_read_data (tmp / phpTBAlvX): Process tag (x010D = DocumentNam): Illegal components (0)

2. Use the @ operator to hide the warning:

 $exif = @exif_read_data(tmp/phpTBAlvX); 

RESULT: $ exif as an array with 20 arguments, but it does not have 'DateTimeOriginal'

  Array ( [FileName] => phphT9mZy [FileDateTime] => 1529171254 ... [SectionsFound] => ANY_TAG, IFD0, EXIF [COMPUTED] => Array ( [html] => width="3968" height="2976" [Height] => 2976 [Width] => 3968 ... ) [ImageWidth] => 3968 [ImageLength] => 2976 [BitsPerSample] => Array() [ImageDescription] => cof [Make] => HUAWEI ... [DateTime] => 2018:06:14 12:00:38 [YCbCrPositioning] => 1 ) 

3. End of decision:

 $img = new \Imagick(tmp/phpTBAlvX); $allProp = $img->getImageProperties(); $exifProp = $img->getImageProperties("exif:*"); 

RESULT: $ allProp as an array with 70 arguments with 'DateTimeOriginal'

 Array ( [date:create] => 2018-06-16T21:15:24+03:00 [date:modify] => 2018-06-16T21:15:24+03:00 [exif:ApertureValue] => 227/100 [exif:BitsPerSample] => 8, 8, 8 ... [exif:DateTimeOriginal] => 2018:06:14 12:00:38 [jpeg:colorspace] => 2 [jpeg:sampling-factor] => 2x2,1x1,1x1 ) 

RESULT: $ exifProp as an array with 66 arguments with 'DateTimeOriginal'

 Array ( [exif:ApertureValue] => 227/100 [exif:BitsPerSample] => 8, 8, 8 ... [exif:DateTimeOriginal] => 2018:06:14 12:00:38 ) 

MY DECISION:

  1. never use @ to suppress any warning or code
  2. use the Imagick class to get any image tag
+1
source share

All Articles