[ACCEPTED]-PHP/(bad) exif data/warnings, what to do?-exif

Accepted answer
Score: 34

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

$exif = @exif_read_data(..);

That's better 3 than setting display_errors because it silences warnings/errors 2 on the exif read function only, and does 1 not hide other possible errors in your code.

Score: 6

Despite this is on old topic, it came for 12 me out of nowhere with new php 7.2: Bug #75785 Many errors from exif_read_data

I agree 11 with @maraspin, as any error is for a reason 10 and not dealing with it means having poor 9 performance (time, features).

MY GOAL: to get 'DateTimeOriginal' of 8 uploadable image (and not just creation_date 7 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 6 exif_read_data(tmp/phpTBAlvX): Process 5 tag(x010D=DocumentNam): Illegal components(0)

2. Using the @ operator to hide the warning:

$exif = @exif_read_data(tmp/phpTBAlvX);

RESULT: $exif 4 as array with 20 arguments, but no 'DateTimeOriginal' in 3 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 2 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 1 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:

  1. never use @ for suppressing any warning or code
  2. use The Imagick class for getting any tag of an image

More Related questions