Hallo,
ich bin auf der Suche nach einer Lösung für mein IPTC-problem. Ich kann auf meinem Server problemlos IPTC-Informationen auslesen. Schreiben klappt jedoch überhaupt nicht. Ich habe alle im Internet zu findenden Script ausgetestet. Das Ergebnis ist jedoch immer das gleiche. Im neuen Bild sind keine IPTC-Informationen mehr enthalten. Mir fällt dazu einfach nichts mehr ein. Vielleicht hat jemand hier auch schon mit diesem Thema Erfahrung und kann mir weiterhelfen.
Hier mein Test-Script:
<?php
// 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;
}
?>
Bei mir tut es leider nicht. das neue Bild enthält keine IPTC-Informationen.
Gruß Tobias Klepp