Chapter 9. Exif Functions

6 views
Skip to first unread message

Pterodactyl

unread,
May 28, 2007, 7:39:33 AM5/28/07
to Dive Into PHP 5: The Graphics
Chapter 9. Exif Functions

Table of Contents

read_exif_data()
exif_imagetype()
exif_read_data()
exif_thumbnail()
exif_tagname()

This chapter describes all functions defined in the Exif extension. [2]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#php_manual]

read_exif_data()

The read_exif_data() function is just an alias of exif_read_data()
(see the section called "exif_read_data()").

exif_imagetype()

The exif_imagetype() function determines the type of an image.

The function reads the first bytes of an image and checks its
signature. It can be used to avoid calls to other exif functions with
unsupported file types or in conjunction with $_SERVER['HTTP_ACCEPT']
to check whether or not the viewer is able to see a specific image in
the browser.

int exif_imagetype ( filename);
string filename;

filename. The image being checked.

Return Values. When a correct signature is found, the appropriate
constant value will be returned (see the section called "Resources and
Constants" [http://pterodactyl.l2p.net/book/php5image/page/
ch08s04.html]) otherwise the return value is false.

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

The return value is the same value that getimagesize() (see the
section called "getimagesize()" [http://pterodactyl.l2p.net/book/
php5image/page/ch11s02.html]) returns in index 2 but exif_imagetype()
is much faster.

Example 9.1. The exif_imagetype() function

if (exif_imagetype('image.png') != IMAGETYPE_PNG) {
print 'This image is not a PNG.';
}

exif_read_data()

The exif_read_data() function reads the EXIF headers from a JPEG or
TIFF image file.
array exif_read_data ( filename,
sections,
arrays,
thumbnail);
string filename;
string sections;
bool arrays;
bool thumbnail;

filename. The name (not URL) of the image file.

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. Possible section
names are FILE, COMPUTED, ANY_TAG, IFD0 (IFD1), THUMBNAIL, COMMENT,
and EXIF.

arrays. Specifies whether or not each section becomes an array. The
sections COMPUTED, THUMBNAIL, and COMMENT always become arrays as they
may contain values whose names conflict with other sections.

thumbnail. When set to true the thumbnail itself is read. Otherwise,
only the tagged data is read.

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

The first parameter is only required; the rest are optional.

Return Values. It returns an associative array 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, exif_read_data() will
return false.

Example 9.2. The exif_read_data() function

print_r(exif_read_data('pterodactyl.jpg'));

Array
(
[FileName] => pterodactyl.jpg
[FileDateTime] => 1154441934
[FileSize] => 11970
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] =>
[COMPUTED] => Array
(
[html] => width="263" height="211"
[Height] => 211
[Width] => 263
[IsColor] => 0
)

)

exif_thumbnail()

The exif_thumbnail() function retrieves the embedded thumbnail of a
TIFF or JPEG image.
string exif_thumbnail() ( filename,
&width,
&height,
&imagetype);
string filename;
int &width;
int &height;
int &imagetype;

filename. The name of the image file being read. This image contains
an embedded thumbnail.

width. The return width of the returned thumbnail.

height. The returned height of the returned thumbnail.

imagetype. The returned image type of the returned thumbnail. This is
either TIFF or JPEG.

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

The first parameter is only required; the rest are optional.

Return Values. Returns the embedded thumbnail, or false if the image
contains no thumbnail.

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

It is possible that exif_thumbnail() cannot create an image but can
determine its size. In this case, the return value is false but width
and height are set.

Example 9.3. The exif_thumbnail() function

<?php

if ($thumbnail = exif_thumbnail('image.jpg')) {
header('Content-type: image/jpeg');
print $thumbnail;
} else {
print 'No thumbnail available.';
}

?>


1

If you want to deliver thumbnails through the exif_thumbnail()
function, you should send the mimetype information using the header()
function.

exif_tagname()

The exif_tagname() function gets the header name for an index.
string exif_tagname ( index);
string index;

index. The image index.

Return Values. Returns the header name, or false if index is
undefined.

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

This function is currently not documented.

Reply all
Reply to author
Forward
0 new messages