note 32622 deleted from function.iptcparse by alindeman
| From: | alindeman@php.net | Date: | Tue, 03 Jun 2003 12:44:10 +0000 |
| Subject: | note 32622 deleted from function.iptcparse by alindeman | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-49620@lists.php.net to get a copy of this message | ||
Note Submitter: torfi@goobubble.com
----
Here´s a little function to return a more comfortable associative array of IPTC fields in an image.
Probably not perfect but working for me... of course I used the examples from the above posters as
a starter - thanks for that!
--- code ---
// getiptcinfo(pathtoimage)
// returns associative array of IPTC-Header if available, or false on failure
// hash fields are named as specified in IPTC sample c++ code
// see http://www.iptc.org/site/iimphotocpp.zip
//
function getiptcinfo($imagepath) {
// $_iptcmap is a hash of IPTC-codes resolving to names
$_iptcmap=Array("2#120"=>"caption",
"2#005"=>"graphic_name",
"2#010"=>"urgency",
"2#015"=>"category",
"2#020"=>"supp_categories",
"2#025"=>"keywords",
"2#040"=>"spec_instr",
"2#055"=>"creation_date",
"2#060"=>"creation_time",
"2#065"=>"orig_program",
"2#080"=>"byline",
"2#085"=>"bytitle",
"2#090"=>"city",
"2#095"=>"state",
"2#095"=>"country",
"2#101"=>"country",
"2#103"=>"transref",
"2#105"=>"headline",
"2#110"=>"credit",
"2#115"=>"source",
"2#120"=>"caption",
"2#122"=>"caption_writer");
if(is_readable($imagepath)) {
$size = GetImageSize($imagepath,&$myinfo);
if($myinfo["APP13"]) {
$iptc = iptcparse ($myinfo["APP13"]);
if(is_array($iptc)) {
$retval=array();
foreach($iptc as $iptckey=>$iptcvalue) {
$temp='';
if(is_array($iptcvalue)) {
if(count($iptcvalue)>1) {
$temp=$iptcvalue;
} else {
$temp=$iptcvalue[0];
}
if($_iptcmap[$iptckey]) {
$retval[$_iptcmap[$iptckey]]=$temp;
} else {
if(preg_match("/\#(\d+)/",$iptckey,$match)) {
$retval[$match[1]]=$temp;
} else {
$retval[$iptckey]=$temp;
}
}
}
}
} else {
$retval=false;
}
} else {
$retval=false;
}
} else {
$retval=false;
}
return $retval;
}