note 18549 added to function.iptcembed

From: Date: Sun, 27 Jan 2002 20:45:36 +0000
Subject: note 18549 added to function.iptcembed
Groups: php.notes 
Request: Send a blank email to php-notes+get-25872@lists.php.net to get a copy of this message
Example to read IPTC text from an image, changing the text an write to a new file using the functions iptcparse and iptcembed. Also a list of the most common IPTC fields. <? // original file name $image_name_old = "test.jpg"; // New file name $image_name_new = "test2.jpg"; // Reads the IPTC text in to the array '$iptc' // The number after the '#' is the IPTC field // Ex: $iptc["2#120"][0] is Caption // $iptc["2#055"][0]; is Creation date $size = GetImageSize ("$image_name_old",&$info); $iptc_old = iptcparse ($info["APP13"]); // Adding or replacing IPTC text // This ex. replace the original category or create it if it dos not exist $iptc_old["2#015"][0] = "Sport"; // .. and adding more text to the original caption $iptc_old["2#120"][0] .= " More caption text"; // Making the new IPTC string foreach (array_keys($iptc_old) as $s){ // Finds the IPTC numbers $tag = str_replace("2#", "", $s); // Creating the string $iptc_new .= iptc_maketag(2, $tag, $iptc_old[$s][0]); } // The original file and the new IPTC Text into $content // Mode 0 - puts the image file into $content // Mode 1 - puts the image file into $content and directly to the web client // Mode 2 - puts the image file to web client $mode = 0; $content = iptcembed($iptc_new, $image_name_old, $mode); // writes the new file $fp = fopen($image_name_new, "w"); fwrite($fp, $content); fclose($fp); // Function to format the new IPTC text, (thanks to Thies C. Arntzen) function iptc_maketag($rec,$dat,$val){ $len = strlen($val); if ($len < 0x8000) return chr(0x1c).chr($rec).chr($dat). chr($len >> 8). chr($len & 0xff). $val; else return chr(0x1c).chr($rec).chr($dat). chr(0x80).chr(0x04). chr(($len >> 24) & 0xff). chr(($len >> 16) & 0xff). chr(($len >> 8 ) & 0xff). chr(($len ) & 0xff). $val; } ?> --- The most common IPTC Fileds 005 - Object Name 007 - Edit Status 010 - Priority 015 - Category 020 - Supplemental Category 022 - Fixture Identifier 025 - Keywords 030 - Release Date 035 - Release Time 040 - Special Instructions 045 - Reference Service 047 - Reference Date 050 - Reference Number 055 - Created Date 060 - Created Time 065 - Originating Program 070 - Program Version 075 - Object Cycle 080 - Byline 085 - Byline Title 090 - City 095 - Province State 100 - Country Code 101 - Country 103 - Original Transmission Reference 105 - Headline 110 - Credit 115 - Source 116 - Copyright String 120 - Caption 121 - Local Caption -- http://www.php.net/manual/en/function.iptcembed.php http://master.php.net/manage/user-notes.php?action=edit+18549 http://master.php.net/manage/user-notes.php?action=delete+18549 http://master.php.net/manage/user-notes.php?action=reject+18549

« previous php.notes (#25872) next »