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!
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
Try this:
$size = getimagesize( 'DSC4008.jpg', $iptch );
$iptc = isset( $iptch['APP13'] ) ? iptcparse( $iptch['APP13'] ) : false;
$name = isset( $iptc['2#005'] ) ? $iptc['2#005'][0] : 'Undefined';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With