Get iptc metadata of jpg image in php

silverchair picture silverchair · Nov 26, 2012 · Viewed 7.5k times · Source

I'm trying to get some iptc metadata from jpg image (http://pepeliana.com/images/DSC4008.jpg) with php. The Title metadata of the referenced image is set to "Testing". I've went through the php manual and both functions that seemed to do the job - iptcparse() and exif_read_data(). Both functions are enabled in php. However for the life of me, I can't figure out, why both functions do not return the desired data. Here is a sample code I've tried and I should also mention that I've also tried this code on several images that have Title iptc metadata (thus excluding the possibility of a corrupted image or improperly set metadata):

<?php 
$size = getimagesize ('DSC4008.jpg', $info);       
 if(is_array($info)) {   
    $iptc = iptcparse($info["APP13"]);
    foreach (array_keys($iptc) as $s) {             
        $c = count ($iptc[$s]);
        for ($i=0; $i <$c; $i++)
        {
            echo $s.' = '.$iptc[$s][$i].'<br>';
        }
    }                 
}
 ?>

also:

<?php
$exif = exif_read_data('DSC4008.jpg', 0, true);
echo $exif['WINXP']['Title'];
?>

As you can see, this is as simple as it gets, yet, I cannot get either to return what I want. Clearly I must be missing something obviously simple, no? Please help!

Answer

Stefan picture Stefan · Nov 26, 2012

You have set the ImageDescription of your image to "Testing"
This here will work:

$exif = exif_read_data('1.jpg','IFD0',true);
echo $exif["IFD0"]["ImageDescription"];

echoes

Testing