exif_read_data 


php apg

READS the EXIF headers of an image file, this means reading the metadata generated by digital cameras.




This function returns an associative ARRAY where the ARRAY indexes are the header names and the ARRAY values are the values associated with those headers.

This function will return FALSE if no data can be returned.

This functions also validates EXIF data tags according to the EXIF specification.


<?php

array|false exif_read_dataresource|string $file,
                                                        ?
string $required_sections null,
                                                           
bool $as_arrays false,
                                                           
bool $read_thumbnail false
)


where,

$file The location of the image file

$required_sections 
A comma separated list of sections
                                 
SEE the below TABLE )
                 
$as_arrays To control if each section 
                     becomes an 
ARRAY or STRINGS

$read_thumbnail 
To control whether thumbnails 
                              are displayed 
or not

?>

  $file   


The location of the image file.

This can either be a path to the file (stream wrappers are also supported as usual) or a stream resource.



STREAM WRAPPERS MEANING
file:// LOCAL File System
http:// URL HTTP
ftp:// URL FTP
php:// I/O streams
zlib:// Data Compression stream
data:// DATA (RFC-2397)
glob:// Find Filenames
phar:// PHP Archive
ssh2:// Secure Shell 2
rar:// RAR
ogg:// Audio
expect:// Interaction of stream processes
ed48

  $required_sections   


A comma separated list of sections that need to be present in file to produce a result array.

If none of the requested sections could be found the return value is FALSE.



SECTION MEANING DEFAULT
FILE FileName, FileSize, FileDateTime, SectionsFound NULL
COMPUTED html, Width, Height, IsColor, and more if available. Height and Width are computed the same way getimagesize()
does so their values must not be part of any header returned.
Also, html is a height/width text string to be used inside normal HTML.
ANY_TAG Any tagged information.
IFD0 Specifically IFD0 data.
In normal image files, primary information.
THUMBNAIL Any image file that has a built-in thumbnail has
an additional IFD for its storage.
COMMENT Comment headers of JPEG images.
EXIFA subsection of IFD0.
Contains most of the information about the object image.
Most of this information is provided by the digital camera used.
ed48

  $as_arrays   


Specifies whether or not each section becomes an ARRAY.

The $required_sections COMPUTED, THUMBNAIL, and COMMENT always become ARRAYS as they may contain values whose names conflict with other sections.



VALUE MEANING DEFAULT
1 ( TRUE ) Each section will be treated as ARRAY
Except COMPUTED, THUMBNAIL, and COMMENT.
0 ( FALSE )
0 ( FALSE ) Each section will be treated as STRING.
ed48

  $read_thumbnail   


To control whether thumbnails are displayed or not.



VALUE MEANING DEFAULT
1 ( TRUE ) The thumbnail will be displayed. 0 ( FALSE )
0 ( FALSE ) The thumbnail will not be displayed
ed48

  1 EXERCISE   

<?php

$img_file01 
"E 01.jpg";

echo 
$img_file01 '<br><br>';
echo 
'<img src="img/' $img_file01 '" alt="' 
$img_file01 '" title="' $img_file01 '" width="70%">
<br><br>'
;


$exif_data01 exif_read_data ('img/' $img_file01);

echo 
'<pre>';
print_r ($exif_data01);
echo 
'</pre>';

$exif_data01a exif_read_data ('img/' $img_file01);

echo 
'<pre>';
print_r ($exif_data01a['COMPUTED']);
echo 
'</pre>';

?> 

 RESULT   

E 01.jpg

E 01.jpg apr

Array
(
[FileName] => E 01.jpg
[FileDateTime] => 1549994066
[FileSize] => 2629746
[FileType] => 2
[MimeType] => image/jpeg [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
[COMPUTED] => Array
(
[html] => width="4032" height="3024" [Height] => 3024 [Width] => 4032 [IsColor] => 1 [ByteOrderMotorola] => 1 [ApertureFNumber] => f/2.2 [Thumbnail.FileType] => 2 [Thumbnail.MimeType] => image/jpeg )

[Make] => Apple
[Model] => iPhone SE
[Orientation] => 1
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[Software] => 12.1.4
[DateTime] => 2019:02:12 14:54:26
[YCbCrPositioning] => 1
[Exif_IFD_Pointer] => 206
[GPS_IFD_Pointer] => 1700
[THUMBNAIL] => Array
(
[Compression] => 6
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[JPEGInterchangeFormat] => 2104
[JPEGInterchangeFormatLength] => 15062
)

[ExposureTime] => 1/120
[FNumber] => 11/5
[ExposureProgram] => 2
[ISOSpeedRatings] => 25
[ExifVersion] => 0221
[DateTimeOriginal] => 2019:02:12 14:54:26
[DateTimeDigitized] => 2019:02:12 14:54:26
[ComponentsConfiguration] => 
[ShutterSpeedValue] => 222125/32154
[ApertureValue] => 193685/85136
[BrightnessValue] => 478176/78371
[ExposureBiasValue] => 0/1
[MeteringMode] => 5
[Flash] => 16
[FocalLength] => 83/20
[SubjectLocation] => Array
(
[0] => 2014
[1] => 1510
[2] => 2214
[3] => 1331
)

[MakerNote] => Apple iOS
[SubSecTimeOriginal] => 563
[SubSecTimeDigitized] => 563
[FlashPixVersion] => 0100
[ColorSpace] => 1
[ExifImageWidth] => 4032
[ExifImageLength] => 3024
[SensingMethod] => 2
[SceneType] => 
[ExposureMode] => 0
[WhiteBalance] => 0
[DigitalZoomRatio] => 72/43
[FocalLengthIn35mmFilm] => 49
[SceneCaptureType] => 0
[UndefinedTag:0xA432] => Array
(
[0] => 83/20
[1] => 83/20
[2] => 11/5
[3] => 11/5
)

[UndefinedTag:0xA433] => Apple
[UndefinedTag:0xA434] => iPhone SE back camera 4.15mm f/2.2
[GPSLatitudeRef] => S
[GPSLatitude] => Array
(
[0] => 8/1
[1] => 27/1
[2] => 3100/100
)

[GPSLongitudeRef] => W
[GPSLongitude] => Array
(
[0] => 34/1
[1] => 59/1
[2] => 1452/100
)

[GPSAltitudeRef] =>
[GPSAltitude] => 114067/11777
[GPSTimeStamp] => Array
(
[0] => 17/1
[1] => 54/1
[2] => 2600/100
)

[GPSSpeedRef] => K
[GPSSpeed] => 0/1
[GPSImgDirectionRef] => M
[GPSImgDirection] => 223027/1252
[GPSDestBearingRef] => M
[GPSDestBearing] => 223027/1252
[GPSDateStamp] => 2019:02:12
[UndefinedTag:0x001F] => 5/1
)


Array
(
[html] => width="4032" height="3024"
[Height] => 3024
[Width] => 4032
[IsColor] => 1
[ByteOrderMotorola] => 1
[ApertureFNumber] => f/2.2
[Thumbnail.FileType] => 2
[Thumbnail.MimeType] => image/jpeg
)


  2 EXERCISE   

<?php

$img_file02 
"img/E 02.jpg";
$exif_data02 exif_read_data($img_file02);
echo 
basename($img_file02) . "<br><br>";
echo 
'<img src="' $img_file02 '" alt="' 
$img_file02 '" title="' $img_file02 
'" width="70%"><br><br>';

$it 
new 
RecursiveIteratorIterator
(new RecursiveArrayIterator($exif_data02));
echo 
'<pre>';
foreach(
$it as $key => $value) {
  echo 
"$key$value <br>";   
}
echo 
'</pre>';

?> 

 RESULT   

E 02.jpg

E 02.jpg apr

FileName: E 02.jpg 
FileDateTime: 1549994066
FileSize: 2629746
FileType: 2
MimeType: image/jpeg
SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
html: width="4032" height="3024"
Height: 3024
Width: 4032
IsColor: 1
ByteOrderMotorola: 1
ApertureFNumber: f/2.2
Thumbnail.FileType: 2
Thumbnail.MimeType: image/jpeg
Make: Apple
Model: iPhone SE
Orientation: 1
XResolution: 72/1
YResolution: 72/1
ResolutionUnit: 2
Software: 12.1.4
DateTime: 2019:02:12 14:54:26
YCbCrPositioning: 1
Exif_IFD_Pointer: 206
GPS_IFD_Pointer: 1700
Compression: 6
XResolution: 72/1
YResolution: 72/1
ResolutionUnit: 2
JPEGInterchangeFormat: 2104
JPEGInterchangeFormatLength: 15062
ExposureTime: 1/120
FNumber: 11/5
ExposureProgram: 2
ISOSpeedRatings: 25
ExifVersion: 0221
DateTimeOriginal: 2019:02:12 14:54:26
DateTimeDigitized: 2019:02:12 14:54:26
ComponentsConfiguration: 
ShutterSpeedValue: 222125/32154
ApertureValue: 193685/85136
BrightnessValue: 478176/78371
ExposureBiasValue: 0/1
MeteringMode: 5
Flash: 16
FocalLength: 83/20
0: 2014
1: 1510
2: 2214
3: 1331
MakerNote: Apple iOS
SubSecTimeOriginal: 563
SubSecTimeDigitized: 563
FlashPixVersion: 0100
ColorSpace: 1
ExifImageWidth: 4032
ExifImageLength: 3024
SensingMethod: 2
SceneType: 
ExposureMode: 0
WhiteBalance: 0
DigitalZoomRatio: 72/43
FocalLengthIn35mmFilm: 49
SceneCaptureType: 0
0: 83/20
1: 83/20
2: 11/5
3: 11/5
UndefinedTag:0xA433: Apple
UndefinedTag:0xA434: iPhone SE back camera 4.15mm f/2.2
GPSLatitudeRef: S
0: 8/1
1: 27/1
2: 3100/100
GPSLongitudeRef: W
0: 34/1
1: 59/1
2: 1452/100
GPSAltitudeRef:
GPSAltitude: 114067/11777
0: 17/1
1: 54/1
2: 2600/100
GPSSpeedRef: K
GPSSpeed: 0/1
GPSImgDirectionRef: M
GPSImgDirection: 223027/1252
GPSDestBearingRef: M
GPSDestBearing: 223027/1252
GPSDateStamp: 2019:02:12
UndefinedTag:0x001F: 5/1


  3 EXERCISE   

<?php

$img_file 
"img/E 03.THM";
$exif_data exif_read_data($img_file);
echo 
$img_file "<br><br>";
echo 
'<img src="' $img_file '" alt="' 
$img_file ' apr' '" title="' $img_file '" width="160"><br><br>';

$it 
new 
RecursiveIteratorIterator
(new RecursiveArrayIterator($exif_data));
echo 
'<pre>';
foreach(
$it as $key => $value) {
  echo 
"$key$value <br>";   
}
echo 
'</pre>';

?>

 RESULT   

E 03.THM

E 03.THM apr

FileName: E 03.THM 
FileDateTime: 1568118868
FileSize: 7828
FileType: 2
MimeType: image/jpeg
SectionsFound: ANY_TAG, IFD0, EXIF, INTEROP
html: width="160" height="120"
Height: 120
Width: 160
IsColor: 1
ByteOrderMotorola: 0
Make: SONY
Model: DSC-T50
Orientation: 1
XResolution: 72/1
YResolution: 72/1
ResolutionUnit: 2
DateTime: 2009:11:30 15:18:25
YCbCrPositioning: 2
Exif_IFD_Pointer: 172
ExifVersion: 0221
DateTimeOriginal: 2009:11:30 15:18:25
DateTimeDigitized: 2009:11:30 15:18:25
ComponentsConfiguration: 
FlashPixVersion: 0100
ColorSpace: 1
ExifImageWidth: 160
ExifImageLength: 120
InteroperabilityOffset: 326
InterOperabilityIndex: THM
InterOperabilityVersion: 0100

  4 EXERCISE   

<?php

// Run this code to see the same as the previous exercise

$img_file "img/E 03.THM";

echo 
$img_file "<br><br>";
echo 
'<img src="' $img_file '" alt="' 
$img_file ' apr' '" title="' $img_file '" width="160"><br><br>';

$fp fopen($img_file'rb');

echo 
'<pre>';
var_dump(exif_read_data($fp));
echo 
'</pre>';

fclose($fp);

?>