Example 1. exif_read_data() example
<?php
echo "test1.jpg:<br />\n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n"
: "Image contains headers<br />";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>
The first call fails because the image has no header information.
test1.jpg:
No header data found.
test2.jpg:
FILE.FileName: test2.jpg
FILE.FileDateTime: 1017666176
FILE.FileSize: 1240
FILE.FileType: 2
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT
COMPUTED.html: width="1" height="1"
COMPUTED.Height: 1
COMPUTED.Width: 1
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.UserComment: Exif test image.
COMPUTED.UserCommentEncoding: ASCII
COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger.
COMPUTED.Copyright.Photographer: Photo (c) M.Boerger
COMPUTED.Copyright.Editor: Edited by M.Boerger.
IFD0.Copyright: Photo (c) M.Boerger
IFD0.UserComment: ASCII
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.JPEGInterchangeFormatLength: 523
COMMENT.0: Comment #1.
COMMENT.1: Comment #2.
COMMENT.2: Comment #3end
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.Thumbnail.Height: 1
THUMBNAIL.Thumbnail.Height: 1
Note: If the image contains any IFD0 data then COMPUTED
contains the entry ByteOrderMotorola which is 0 for little-endian
(intel) and 1 for big-endian (motorola) byte order. This
was added in PHP 4.3.
When an Exif header contains a Copyright note this itself
can contain two values. As the solution is inconsistent
in the Exif 2.10 standard the COMPUTED section will return
both entries Copyright.Photographer and Copyright.Editor
while the IFD0 sections contains the byte array with the
NULL character that splits both entries. Or just the first
entry if the datatype was wrong (normal behaviour of Exif).
The COMPUTED will contain also an entry Copyright Which
is either the original copyright string or it is a comma
separated list of photo and editor copyright.
Note: The tag UserComment has the same problem as the Copyright
tag. It can store two values first the encoding used and
second the value itself. If so the IFD section only contains
the encoding or a byte array. The COMPUTED section will
store both in the entries UserCommentEncoding and UserComment.
The entry UserComment is available in both cases so it should
be used in preference to the value in IFD0 section.
If the user comment uses Unicode or JIS encoding and the
module mbstring is available this encoding will automatically
changed according to the exif ini settings in the php.ini.
This was added in PHP 4.3.
Note: 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.
Note: Starting from PHP 4.3 the function can read all embedded
IFD data including arrays (returned as such). Also the size
of an embedded thumbnail is returned in THUMBNAIL subarray
and the function exif_read_data() can return thumbnails
in TIFF format. Last but not least there is no longer a
maximum length for returned values (not until memory limit
is reached).
Note: This function is only available in PHP 4 compiled
using --enable-exif. Its functionality and behaviour has
changed in PHP 4.2. Earlier versions are very unstable.
Since PHP 4.3 user comment can automatically change encoding
if PHP 4 was compiled using --enable-mbstring.
This function does not require the GD image library.
See also exif_thumbnail() and getimagesize().