Reputation: 467
I'm writing a small script that gathers a couple exif values from images... namely the creation date, make and model.
I'm noticing (particularly with image mailed through the default iPhone mail app) that the exif data has been altered, which is a known issue (the mail app compresses images before sending them, even when 'full size' is selected). The values I'm looking for appear to be there, although I get PHP warnings accessing them. No problems actually getting the values, but the warning obviously isn't working for me.
Calling ini_set('display_errors',0) hides the warnings, but seems sloppy to me. Is there any way I can ignore this warning, on this script, for this scenario that is a little better?
My initial thought was wrapping everything in a try/catch, but the warning is still displayed prominently on the page.
I'm simply using the standard exif_read_data() function, I think an external library would be a little much for what little 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); } }
Warning:
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
Upvotes: 8
Views: 16786
Reputation: 91
Despite this is on old topic, it came for me out of nowhere with new php 7.2: Bug #75785 Many errors from exif_read_data
I agree with @maraspin, as any error is for a reason and not dealing with it means having poor performance (time, features).
MY GOAL: to get 'DateTimeOriginal' of uploadable image (and not just creation_date of tmp file - DateTime).
1. Normal using 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. Using the @ operator to hide the warning:
$exif = @exif_read_data(tmp/phpTBAlvX);
RESULT: $exif as array with 20 arguments, but no 'DateTimeOriginal' in it
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. Ended with solution:
$img = new \Imagick(tmp/phpTBAlvX);
$allProp = $img->getImageProperties();
$exifProp = $img->getImageProperties("exif:*");
RESULT: $allProp as 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 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:
Upvotes: 7
Reputation: 31108
You can use the @ operator to hide the warning without using display_errors, i.e.
$exif = @exif_read_data(..);
That's better than setting display_errors
because it silences warnings/errors on the exif read function only, and does not hide other possible errors in your code.
Upvotes: 35