exif_read_data
exif_read_data
Reads the EXIF headers from an image file
**exif_read_data** $file $required_sections bool $as_arrays bool $read_thumbnail
reads the
headers from an image file. This way you can read meta data
generated by digital cameras.
exif_read_data
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.
and are computed the
same way does so their values must not be
part of any header returned. Also, is a
height/width text string to be used inside normal .
Height``Width``getimagesize``html
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
section will return both entries
and
while the
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 will also contain the entry
which is either the original copyright string,
or a comma separated list of the photo and editor copyright.
COMPUTED``Copyright.Photographer``Copyright.Editor``IFD0``COMPUTED``Copyright
The tag 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 section only contains the encoding
or a byte array. The section will store both in
the entries and
. The entry
is available in both cases so it should be used in preference to the value
in section.
UserComment``IFD``COMPUTED``UserCommentEncoding``UserComment``UserComment``IFD0
also validates EXIF data tags according
to the EXIF specification (, page 20).
exif_read_dataurl.exifspec
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
required_sections
Is a comma separated list of sections that need to be present in file
to produce a result . If none of the requested
sections could be found the return value is false.
`array`
as_arrays
Specifies whether or not each section becomes an array. The
,
, and
always become arrays as they may contain values whose names conflict
with other sections.
required_sections``COMPUTED``THUMBNAIL``COMMENT
read_thumbnailWhen set to true the thumbnail itself is read. Otherwise, only the
tagged data is read.
It returns an associative where the array indexes are
the header names and the array values are the values associated with
those headers. If no data can be returned,
will return false.
array``exif_read_data
Errors of level and/or
may be raised for unsupported tags or other potential error conditions, but the
function still tries to read all comprehensible information.
E_WARNING``E_NOTICE
Voorbeeld: 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 />\n";
$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
Voorbeeld: with streams available as of PHP 7.2.0
<?php
// Open a the file, this should be in binary mode
$fp = fopen('/path/to/image.jpg', 'rb');
if (!$fp) {
echo 'Error: Unable to open image for reading';
exit;
}
// Attempt to read the exif headers
$headers = exif_read_data($fp);
if (!$headers) {
echo 'Error: Unable to read exif headers';
exit;
}
// Print the 'COMPUTED' headers
echo 'EXIF Headers:' . PHP_EOL;
foreach ($headers['COMPUTED'] as $header => $value) {
printf(' %s => %s%s', $header, $value, PHP_EOL);
}
?>
EXIF Headers:
Height => 576
Width => 1024
IsColor => 1
ByteOrderMotorola => 0
ApertureFNumber => f/5.6
UserComment =>
UserCommentEncoding => UNDEFINED
Copyright => Denis
Thumbnail.FileType => 2
Thumbnail.MimeType => image/jpeg
Opmerking: > If is enabled, exif will attempt to process the unicode and pick a charset as specified by and . The exif extension will not attempt to figure out the encoding on its own, and it is up to the user to properly specify the encoding for which to use for decoding by setting one of these two ini directives prior to calling . mbstringexif.decode_unicode_motorolaexif.decode_unicode_intel
exif_read_data
Opmerking: > If the is used to pass a stream to this function, then the stream must be seekable. Note that the file pointer position is not changed after this function returns.
file
exif_thumbnail``getimagesize