IPTC and GetImageSize() problem
| From: | Jakob Öhman | Date: | Thu, 08 May 2003 18:59:59 +0000 |
| Subject: | IPTC and GetImageSize() problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146902@lists.php.net to get a copy of this message | ||
Hi!
I've done some simple functions to write and read IPTC data from jpeg files.
The only problem is that after I've written data to a file for a couple of times the GetImageSize() functions stops returning me the image size. If I then delete the file and copy it there again it starts to work.
I guess it has to be something with the read/write of the files or iptcembed() creates bad code.
Here are the functions:
function getIptcData($image) {
GetImageSize($image,$imageData);
if($iptcData = iptcparse($imageData["APP13"])) {
$keys = array_keys($iptcData);
sort($keys);
foreach($keys as $key)
if($key!="2#000")
$returnData[str_replace("2#", "", $key)]=$iptcData[$key][0];
return($returnData);
}
} function setIptcData($image,$data) {
$iptcData = getIptcData($image);
foreach(array_keys($data) as $key)
$iptcData[$key]=$data[$key];
foreach(array_keys($iptcData) as $key)
$iptcString .= makeIptcTag(2, $key, $iptcData[$key]);
$imageContent = iptcembed($iptcString, $image, 0);
$fp = fopen($image, "wb");
fwrite($fp, $imageContent);
fclose($fp);
}
function makeIptcTag($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} Any ideas? -- /Jakob Öhman - neod - jakob@neod.com24) & 0xff).chr(($len >> 16) & 0xff).chr(($len >> 8 ) & 0xff).chr(($len ) & 0xff).$val;