Description
array
exif_read_data ( string filename [, string sections [, bool arrays [, bool thumbnail]]])
The exif_read_data() function reads the
EXIF headers from a JPEG or TIFF image file_ It returns an associative
array where the indexes are the header names and the values
are the values associated with those headers_ If no data can be returned
the result is FALSE_
filename is the name of the file to read_ This
cannot be an url_
sections is 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_
arrays specifies whether or not each section
becomes an array_ The sections COMPUTED,
THUMBNAIL and COMMENT allways
become arrays as they may contain values whose names are conflict
with other sections_
thumbnail whether or not to read the thumbnail
itself and not only its tagged data_
Nota:
Exif headers tend to be present in JPEG/TIFF images generated by digital
cameras, but unfortunately each digital camera maker has a different
idea of how to actually tag their images, so you can't always rely on
a specific Exif header being present_
Windows ME/XP both can wipe the Exif headers when connecting to a camera_
More information available at http://ww2_canon_europe_com/products/cameras/notices_dig_cam_users.html_
Ejemplo 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 |
|
Nota:
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_
Nota:
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_
Nota:
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_
Nota:
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 legth for returned
values (not until memory limit is reached)_
Nota:
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()_