Extracting the IPTC data from an image in PHP
When you add a caption to an image in Google's Picasa/Picasa2 (and some other image editing programs) the caption is saved in a special spot in the imaged header section called IPTC data.
While creating the IPTC mod for the simple gallery script I had to extract the IPTC information for the title of the image. This allowed me to extract the title from Picasa and included it under my images in my gallery.
What is IPTC?
IPTC stands for International Press Telecommunications Council and is a defined set of medadata mainly used in news organizations for copyright proposes.
Basically its a standard set of attributes for an image.
Some of the attributes that are included in this standard are; datesent, timesent, objectname, editstatus, urgency, category, subcategory, fixture, keyword, reldate, reltime, specinstr, credate, cretime, orgprg, prgver, byline, bytitle, city, sublocation, state, countrycode, countryname, orgtransref, headline, credit, source, copyright, contact, caption, captionwriter, imagetype, orientation, language, subfile, appreserve. for a full list see the REF document on IPTC.
How to I extract IPTC information from an image?
Extracting and altering IPTC information in PHP is very simple with IPTCParse() and IPTCEmbed()
Example: View all available IPCT Data
function output_iptc_data( $image_path ) { $size = getimagesize ( $image_path, $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>'; } } } }
Leave a comment