PHP: iptcembed - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

iptcparse imagexbm

Last updated: Fri, 26 Jan 2007

view this page in

# iptcembed

(PHP 3 >= 3.0.7, PHP 4, PHP 5)

iptcembed -- Embed binary IPTC data into a JPEG image

## Описание

mixed iptcembed ( string iptcdata, string jpeg_file_name [, int spool] )

Внимание
К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

## Список параметров

`iptcdata`

`jpeg_file_name`

`spool`

add a note User Contributed Notes
iptcembed
thomas at anakrome dot net
04-Jul-2005 09:02
`here is a small code to remove all header from a jpg file, including IPTC, Exif, XMP...
function remove_XMP($image_in, $image_dest) {
$filename_in = addslashes($image_in);
list($width, $height) = getimagesize($filename_in);
$image_dest = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename_in);
imagecopyresampled($image_dest, $image, 0, 0, 0, 0, $width, $height,
$width, $height);
imagejpeg($image_dest, $filename);
}
the problem comes from Photoshop CS cannot read IPTC if XMP is present.
removing XMP and other header _before_ adding IPTC with iptcembed is a good way.`
muguran
13-May-2005 01:41
`Pay attention not add codes with length of value equal to 0; the behavior could be strange...
(e.g. $iptc_old["2#015"][0] = "")`
evan at nospam dot ozhiker dot com
09-Aug-2004 09:53
`You might have noticed that several metadata fields in Photoshop are not available via IPTC.
Also, Photoshop now uses XMP for it's primary metadata, meaning IPTC is only read by Photoshop if XMP is not present.
I have written a library "PHP JPEG Metadata Toolkit" which bypasses this problem as it allows reading, writing and interpreting of virtually any type of metadata, including XMP, IPTC and EXIF.
Try it out, and download it at:
http://www.ozhiker.com/electronics/pjmt/index.html`
dj dot cyberdance at gmx dot at
30-May-2004 06:47
`Yep it's me again :-) After some time I spent searching around for other possibilities to write IPTC fields to JPEG files I found this one:
http://www.zonageek.com/software/php/jpeg/index.php
This one seems to work pretty fine, remember that you have to install PEAR to get this running (Debian package php4-pear).`
dj dot cyberdance at gmx dot at
06-May-2004 04:29
`I've spent a whole day debugging my code (that was based on the example below, posted by knut) until I found out, that iptcembed() only works if the image specified in jpeg_file_name already has IPTC fields included.
That means that you cannot write IPTC fields in a jpeg file without preexisting IPTC information in it.
Updating of IPTC fields also worked only with a few files, I don't really know what it depends on whether it works or not. (Well, it depends on the IPTC header, that's for sure :-)
I'm using PHP 4.2.1, maybe this is fixed in more recent versions, but I don't believe...
Nevertheless, here's some piece of code I tried:
I replaced the line
<?
$iptc_old = iptcparse ($info["APP13"]);
?>
from knut's example below with
<?
$iptc_old["2#000"][0] = chr(0) . chr(2);
?>
This creates just an empty "Header" according to the IPTC spec. This one also is included when getting IPTC info using iptcparse(). So my intention was to create a fully new header, but when using iptcembed() afterwards, the file size of the new file was a little smaller than the original but without any IPTC info stored in it.`
pprem at pprem dot net
20-Feb-2004 10:04
`I've a problem with the ltrim fucntion: sometimes it remove more characters than it must, so it's better to delete the line
<?
// $image = rtrim ($image, $endchar);
?>
in the XMP_remove_from_jpeg function`
pprem at pprem dot net
19-Feb-2004 04:10
`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 :-)`
pprem
15-Feb-2004 07:00
`I confirm: Photoshop 7 and other recent Adobe programs use XMP instead of IPTC. They write datas in IPTC format only for compatibility with older programs, but use only XMP.
I'm working on a program that write XMP and IPTC together and probably post it here as soon as possible.`
collord
27-Jan-2004 01:20
`Regarding issues with photoshop IPTC... Photoshop actually prefers a different embedded metadata format, XMP, which is RDF-based. When Photoshop manages metadata via File Info, what you're actually doing is manipulating RDF in a "photoshop" namespace as well as the standard Dublin Core (dc) namespace, and a couple others. When a file is written that supports IPTC, the equivalent fields e.g. copyright, keywords, etc. are serialized into the IPTC block.
So, if one manipulates the IPTC block of a Photoshop-generated image and leaves the XMP block alone, it's my guess that Photoshop will treat data from the XMP as authoritative.
HTH, jerritt`
jofr at gmx dot com
29-Dec-2003 10:42
`I found out, that iptcembed does not overwrite the full IPTC-Tags from Photoshop.
If you modify the IPTC-Tag with iptcembed, Photoshop will still show you the old IPTC-Tag.
Programs like Fotostation works fine.
JO`
bob at lucid-systems dot com
22-Aug-2002 03:37
`The above example doesn't handle keywords properly. The 'create string' code needs to be modified to cater for the array:
$c = count ($iptc_old[$s]);
for ($i=0; $i <$c; $i++)
{
$iptc_new .= iptc_maketag(2, $tag, $iptc_old[$s][$i]);
}`
rupix at rediffmail dot com
28-Jan-2002 04:24
`Windows makes a distinction between 'text' and 'binary' files. So if you run the above code on a windows platform, it will produce a garbled image. To overcome this problem put the file mode in fopen() as 'wb' instead of 'w'.
Cheerio !!
Rupinder`
knut dot satre dot NoSpam at No_Spam dot nord dot no
27-Jan-2002 03:45
`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`
add a note
iptcparse imagexbm

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST