Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get iptc metadata of jpg image in php

Tags:

php

metadata

iptc

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!

like image 624
silverchair Avatar asked Oct 23 '22 00:10

silverchair


2 Answers

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
like image 181
Stefan Avatar answered Oct 31 '22 13:10

Stefan


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';
like image 42
GDY Avatar answered Oct 31 '22 13:10

GDY