Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Exif Functions : exif_read_data

exif_read_data

Reads the EXIF headers from JPEG or TIFF (PHP 4 >= 4.2.0, PHP 5)
array exif_read_data ( string filename [, string sections [, bool arrays [, bool thumbnail]]] )

Example 600. 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 />\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.

The above example will output something similar to:

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 ?>

Code Examples / Notes » exif_read_data

05-mar-2007 07:50

When reading EXIF information from the 'WINXP' group, you may need to change used encoding from the default "ISO-8859-15" to "UTF-8". This can be done in php.ini or in your code:
<?php
   ini_set('exif.encode_unicode', 'UTF-8');
   $exif = exif_read_data('TEST.JPG', 0, true);
   echo $exif['WINXP']['Title'];
?>
Useful documentation about EXIF:
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
See also comments next to XPTitle and XPAuthor.


wdierkes

Using the exif methods to read WINXP data returns unexpected results unless both exif and mbstring are compiled statically.  Please reference the following bug reports:
Bug #31980
Bug #23105

Specifically, the last comment on #23105:
"[8 Apr 2003 4:26pm UTC] edink@php.net
This cannot be fixed due to the fact that mbstring has been removed from PHP core (it has been 'unbundled') and the rest of core files and other extensions cannot use mbstring functionality when it is compiled as a shared library (dll).
"
If exif is compiled statically (--enable-exif) and mbstring compiled as a DSO module (--enable-mbstring=shared) then exif_read_data may only return a single character rather than the entire string.
Compiling both exif and mbstring statically (--enable-exif --enable-mbstring) resolves the issue.


mafo

some cameras (most higher models) have position senzor (gyroskope?) and taking-position is wrote in EXIF, here is simple script for automatic rotating images
<?php
$exif = exif_read_data($filename);
$ort = $exif['IFD0']['Orientation'];
switch($ort)
{
case 1: // nothing
break;
case 2: // horizontal flip
$image->flipImage($public,1);
break;

case 3: // 180 rotate left
$image->rotateImage($public,180);
break;

case 4: // vertical flip
$image->flipImage($public,2);
break;

case 5: // vertical flip + 90 rotate right
$image->flipImage($public, 2);
       $image->rotateImage($public, -90);
break;

case 6: // 90 rotate right
$image->rotateImage($public, -90);
break;

case 7: // horizontal flip + 90 rotate right
$image->flipImage($public,1);
$image->rotateImage($public, -90);
break;

case 8: // 90 rotate left
$image->rotateImage($public, 90);
break;
}
?>
$image->rotateImage() is inspired by example of http://php.net/manual/en/function.imagerotate.php
$image->flipImage() is inspired by http://php.net/manual/en/function.imagecopy.php#42803 (thank you)


gimpster

I've written a library in pure PHP5 for editing EXIF tags. It deals with both reading and writing EXIF tags, and can be downloaded from http://pel.sourceforge.net/

09-aug-2004 06:11

I've just released the "PHP JPEG Metadata Toolkit" which allows reading, writing and displaying of EXIF information, and does not need the --enable-exif option in PHP4.
It has been tested on 466 different models of digital cameras!
It can decode the following EXIF makernotes:
Agfa, Canon, Casio, Contax, Epson, Fujifilm, Konica, Minolta, Kyocera, Nikon, Olympus, Panasonic, Pentax (Asahi), Ricoh and Sony
Additionaly it can decode IPTC, XMP, Photoshop IRB and many other types of JPEG metadata
Try it out, and download it at:
http://www.ozhiker.com/electronics/pjmt/index.html


pekka

For reading EXIF from XMP data embedded by Adobe Photoshop CS, see  http://www.photography-on-the.net/ee/beta/cs_xmp_to_exif.php

noway

Exif is very unstable under php4.1.2
If you have some problem, (the function didnt return anything, like a blocking call) try this:
$file = './image.jpg';
getimagesize ( $file , $info);
$exif = array();
if (isset($info)) {
foreach($info as $key => $val) {
if ($key != 'APP1') { $exif = read_exif_data($file); break; }
}
}
-- Sharp


Change Language


Follow Navioo On Twitter
exif_imagetype
exif_read_data
exif_tagname
exif_thumbnail
read_exif_data
eXTReMe Tracker