note 40047 added to function.iptcembed
| From: | pprem at pprem dot net | Date: | Thu, 19 Feb 2004 21:10:02 +0000 |
| Subject: | note 40047 added to function.iptcembed | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65426@lists.php.net to get a copy of this message | ||
Reading and changing IPTC make no problem with the PEAR function, but recent Adobe software add XMP
datas on JPEG files and read them instead of IPTC datas. If you need to change IPTC on a JPEG file
and want Adobe PS7 read them, you have two solutions:
- writing XMP and IPTC datas
- writing IPTC datas and removing XMP datas
Because I've not enough time to work on XMP datas, I've choosen the second solution. Here
is the result of this work:
<?php
// removing XMP datas from a JPEG file
// (c) Patrick Premartin 19/02/2004
function XMP_remove_from_jpeg (&$image) {
$xmp_str = "http://ns.adobe.com/xap/1.0/";
$xmp_end = "<?xpacket end='w'?>";
$n_str = strpos ($image, $xmp_str);
$n_end = strpos ($image, $xmp_end);
if (($n_str !== false) && ($n_end !== false) && ($n_str < $n_end)) {
$n_str -= 4; // FF E1 .x. .y. (xy is the length of the XMP block -> first char of this block
$n_end += strlen ($xmp_end)-1; // last char of this block
$endchar = $image [$n_str-1];
if ($endchar == " ") {
$endchar = "A";
} else {
$endchar = " ";
}
$xmp_len = $n_end-$n_str+1;
$img_len = strlen ($image);
$len = $img_len - $xmp_len;
for ($i = $n_str; $i < $img_len; $i ++) {
if ($i < $len) {
$image [$i] = $image [$i+$xmp_len];
} else {
$image [$i] = $endchar;
}
}
$image = rtrim ($image, $endchar);
return true;
} else {
return false;
}
}
function XMP_remove_from_jpegfile ($filename_in, $filename_out="") {
if (""==$filename_out) {
$filename_out = $filename_in;
}
if ((""!=$filename_in) && (file_exists ($filename_in)) && (($len_in =
filesize ($filename_in)) > 0)) {
// chargement du fichier en mémoire
$f_in = fopen ($filename_in, "rb");
$img = fread ($f_in, $len_in);
fclose ($f_in);
// suppression du XMP de l'image
if (XMP_remove_from_jpeg ($img)) {
// enregistrement du fichier sur disque
$f_out = fopen ($filename_out, "wb");
fwrite ($f_out, $img, strlen ($img));
fclose ($f_out);
}
}
}
XMP_remove_from_jpegfile ("ps7_hr.jpg", "ps7_hr_.jpg"); // create a new picture
without XMP datas
XMP_remove_from_jpegfile ("ps8_hr.jpg"); // replace the existing file
?>
In the future, I'll work on changing XMP datas and IPTC in the same way and will publish it
ther or as a in PEAR.
May the force be with us :-)
----
Manual Page -- http://www.php.net/manual/en/function.iptcembed.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40047
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40047&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40047&report=yes
Search -- http://master.php.net/manage/user-notes.php