Friday, March 20, 2009

Image processing in php with exif extension

With the exif (Exchangeable Image Information) extension in php you can work with image meta data. Whenever you use any digital camera and take an image meta data information is stored in the image (like image type, resolution, size etc). With php you can extract that information.

Requirements to use exif extention
To enable exif-support, configure PHP with --enable-exif on unix platform.
If you are on windows platform then uncomment the
php_mbstring.dll and
php_exif.dll DLL's in php.ini. Be sure that php_mbstring.dll DLL must be loaded before the php_exif.dll DLL.

List of exif functions
1)exif_imagetype: It read metadata information from image and determines the type of the image (like jpg, gif, bmp etc). The syntax is,
int exif_imagetype ( string $filename );
The possible return values are,

Value Constant
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
4 IMAGETYPE_SWF
5 IMAGETYPE_PSD
6 IMAGETYPE_BMP
7 IMAGETYPE_TIFF_II (intel byte order)
8 IMAGETYPE_TIFF_MM (motorola byte order)
9 IMAGETYPE_JPC
10 IMAGETYPE_JP2
11 IMAGETYPE_JPX
12 IMAGETYPE_JB2
13 IMAGETYPE_SWC
14 IMAGETYPE_IFF
15 IMAGETYPE_WBMP
16 IMAGETYPE_XBM

You can access image type by CONSTANTS also. If the function could not find any it will return FALSE.

2)exif_read_data: This functions returns many information like height, width, digital camera information, copyright information etc of the image after reading the header info of the image.
The syntax is,
array exif_read_data (string $filename , [string $sections= NULL] , [bool $arrays= false] , [bool $thumbnail= false]);

file_name -is the name of the image file for which you want to extract information.
sections part is the combination of

FILE (FileName, FileSize, FileDateTime, SectionsFound)
COMPUTE (html, Width, Height, IsColor, and more)
IFD0 (Image size and others)
THUMBNAIL
COMMENT (Comment headers of JPEG images.)
EXIF (detail info of the image)

arrays -sepecify whether each section becomes an array)

thumbnail- If true then thumbnail itself is read.

3)exif_tagname: It takes image index and return header name.
The syntax is, string exif_tagname ( int $index );

4)exif_thumbnail: It retrieves the embedded thumbnail of either tiff or jpeg type image.
The syntax is,
string exif_thumbnail(string $filename, [int &$width], [int &$height,[int &$imagetype);

5)read_exif_data: It is same as exif_read_data.

All these examples are given in the post

No comments:

Post a Comment