Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Image Functions : iptcparse

iptcparse

Parse a binary IPTC block into single tags. (PHP 4, PHP 5)
array iptcparse ( string iptcblock )


Code Examples / Notes » iptcparse

evan

You might have noticed that several metadata fields in Photoshop are not available via IPTC.
I have written a library "PHP JPEG Metadata Toolkit" which fixes this problem as it allows reading, writing and interpreting of virtually any type of metadata, including these missing fields.
Try it out, and download it at:
http://www.ozhiker.com/electronics/pjmt/index.html


06-feb-2004 07:17

View all availiable 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].'
';
}
}
}
}


michael wells

To import IPTC keywords (which are stored in an array) into a scalar, try this sort of approach:
$keywordcount = count($iptc["2#025"]);
for ($i=0; $i<$keywordcount; $i++) $keywords .= $iptc["2#025"][$i] . " ";
(you could strip the trailing space if you wanted).
If you are importing data from some Mac applications, they may put chr(213) into strings to access a closing quote character. This prints as a captial O with a tilde above it in a web browser or on Windows. You can fix this with:
function ConvertChars($in)
{
       return str_replace(chr(213),"'",$in);
}
We use aspects of this code at www.thirdlight.com when parsing IPTC tags. XMP seems to be the better solution these days (being XML based is a great improvement!!).


pkrohn

This took me longer than it ought to to figure out. Very handy for handling a stream of photos where the info you want is in the IPTC header. This example passes by reference, for which PHP4 will yell at you. If your need to write into the header, check out the Image::IPTCInfo Perl module.
$size = GetImageSize ("$image_name",&$info);
$iptc = iptcparse ($info["APP13"]);
if (isset($info["APP13"])) {
   $iptc = iptcparse($info["APP13"]){
       if (is_array($iptc)) {
       $caption = $iptc["2#120"][0];
$graphic_name = $iptc["2#005"][0];
$urgency = $iptc["2#010"][0];
$category = $iptc["2#015"][0];
// note that sometimes supp_categories contans multiple entries
$supp_categories = $iptc["2#020"][0];
$spec_instr = $iptc["2#040"][0];
$creation_date = $iptc["2#055"][0];
$photog = $iptc["2#080"][0];
$credit_byline_title = $iptc["2#085"][0];
$city = $iptc["2#090"][0];
$state = $iptc["2#095"][0];
$country = $iptc["2#101"][0];
$otr = $iptc["2#103"][0];
$headline = $iptc["2#105"][0];
$source = $iptc["2#110"][0];
$photo_source = $iptc["2#115"][0];
$caption = $iptc["2#120"][0]; }}


26-apr-2002 03:28

Just to add to the above response, he missed a couple of IPTC tags:
Keywords:
$iptc["2#025"][n];   (there is a list of keywords)
Caption Writer:
$iptc["2#122"][0];
Just figured I'd note it, as the keywords can be quite important for database applications.  I got these by extracting IPTC tags from a Photoshop 6.0 file, so hopefully they are standardized ;)


scin

If you are not sure where a particular value you entered into the IPTC block in photoshop or any other software is being stored, simply run a foreach loop thru the block and find out:
(Insert a new paragraph in the beggening of the first echo)
$size = GetImageSize ("testimg.jpg", &$info);
$iptc = iptcparse($info["APP13"]);
foreach($iptc as $key => $value)
{
echo "<b>IPTC Key:</b> $key <b>Contents:</b> ";
foreach($value as $innerkey => $innervalue)
{
if( ($innerkey+1) != count($value) )
echo "$innervalue, ";
else
echo "$innervalue";
}
}


Change Language


Follow Navioo On Twitter
gd_info
getimagesize
image_type_to_extension
image_type_to_mime_type
image2wbmp
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagesetbrush
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp
eXTReMe Tracker