Java code to write IPTC data to JPG in PhotoShop format

B
Posted By
Bob
Feb 7, 2004
Views
1401
Replies
9
Status
Closed
I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop has in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has been asked several times before but there have been no answers. Is is possible to do this in Java?

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

M
mscir
Feb 7, 2004
http://reader.imagero.com/

Bob wrote:

I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop has in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has been asked several times before but there have been no answers. Is is possible to do this in Java?

B
Bob
Feb 7, 2004
"mscir" wrote in message
http://reader.imagero.com/

Bob wrote:

I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop
has
in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has
been
asked several times before but there have been no answers. Is is
possible
to do this in Java?

Unfortunately….

"ImageroReader (IR) is in Java written library for *READING* of image files."

As far as I can tell, reading is easy. I’ve come across a dozen resources for that. I think that perhaps less than a dozen people on the face on the planet know how to write IPTC data to a JPG file and they all work for the CIA and they’re not telling (Homeland security issue, you understand).
M
mscir
Feb 8, 2004
Bob wrote:
"mscir" wrote in message

http://reader.imagero.com/

Bob wrote:

I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop

has

in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has

been

asked several times before but there have been no answers. Is is

possible

to do this in Java?

Unfortunately….

"ImageroReader (IR) is in Java written library for *READING* of image files."

As far as I can tell, reading is easy. I’ve come across a dozen resources for that. I think that perhaps less than a dozen people on the face on the planet know how to write IPTC data to a JPG file and they all work for the CIA and they’re not telling (Homeland security issue, you understand).

Sorry, I didn’t interpret your original message correctly. Don’t know about writing to it.
T
toby
Feb 8, 2004
"Bob" …
I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop has in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has been asked several times before but there have been no answers. Is is possible to do this in Java?

Some time ago I e-mailed you C code which builds the IPTC record in Photoshop’s required format (see below). If you translate this to Java, and add code to insert the IPTC into the JPEG, it’s done.

T

/*
This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2002-4 Toby Thain,

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/* … */

/* Append a standard tag to the IPTC data. Pass in a pointer to the current end of the data; the function returns the updated end pointer. */

char *add_tag(char *p,int recnum,int marker,
int datasetnum,char *s,int n){
// standard dataset tag
*p++ = marker;
*p++ = recnum;
*p++ = datasetnum;
*p++ = n>>8;
*p++ = n;
// dataset data field
memcpy(p,s,n);
return p+n;
}

/* … */
p = add_tag(p,2,0x1c,0x19, TEXT,LENGTH); /* Photoshop keyword tag */ /* … */
p = add_tag(p, 2,0x1c,0x78, TEXT,LENGTH); /* Photoshop caption tag */
T
toby
Feb 8, 2004
(Toby Thain) wrote in message news:…
"Bob" …
I’m looking for Java code that writes out keywords to JPEG images in PhotoShop format. I’m looking for the same functionality that PhotoShop has in its fileinfo menu.

I’ve searched for this in Google and I’ve seen that this question has been asked several times before but there have been no answers. Is is possible to do this in Java?

Some time ago I e-mailed you C code which builds the IPTC record in Photoshop’s required format (see below). If you translate this to Java, and add code to insert the IPTC into the JPEG, it’s done.

Let’s get specific. You need to add an application specific marker to a JFIF file. The JFIF format spec can be found here:
http://www.ijg.org/files/

The JFIF spec does not mention the APP13 (0xED) marker used by Adobe, but paraphrasing that document, the Photoshop image resources (metadata) marker appears to have the following format:

X’FF’, X’ED’ [=M_APP13], length, identifier, image resources data

length (2 bytes) Total field byte count, including the byte count value (2 bytes), but excluding the
marker itself

identifier This zero terminated string ("Photoshop 3.0") uniquely identifies this marker.
= 50 68 6F 74 6F 73 68 6F 70 20 33 2E 30 00

The content of this marker is the Photoshop image resource data, which is described in the Photoshop SDK ("Photoshop File Formats.pdf", chapter 2).

The IPTC-NAA record (File Info information) is stored as an image resource with ID = 0x0404 (1028). The format of this data is also documented in the SDK ("iimv4.pdf"). Note that Photoshop uses only a small subset of the datasets defined in that document, and uses an application record (2:xx) only; it does not write the object envelope record (1:xx). It uses a tag marker = 0x1c (which I can’t find documented).

Within the IPTC data, several datasets comprise the File Info. The C code posted earlier – which was derived from the IPTC spec – should be sufficient to construct this data.

Note that Photoshop stores many other image resources for different non-pixel parts of the document (paths, for example) – these should be preserved.

In summary, the resulting JPG consists of several nested data formats like the layers of an onion:

JFIF (.JPG):
JFIF APP0 marker
APP13 marker, containing Photoshop image resource data:
image resource ID=1028 (File Info), in IPTC-NAA format:
Application record (2), for example:
Version dataset 2:00 (this is mandatory in the IPTC spec) Keyword dataset(s) 2:25
Caption dataset(s) 2:120
…more datasets…
…more image resources…
…more markers, including JPEG data…
(end)

You may find the IJG Group’s tools and source code (link above) useful, e.g.
djpeg -v test.jpg -outfile /dev/null
gives a rough breakdown of the JFIF contents.

T
PF
Paul Furman
Feb 8, 2004
Toby Thain wrote:
/*
This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2002-4 Toby Thain,

Toby,

Do you know why photoshop uses IPTC format for this instead of exif or where the windows explorer properties are stored? I’m experimenting with using the jpeg comments header instead and I’m not sure which "standard" to adopt. Hmm, I guess that won’t work on tiff or psd though. I’m wanting some fairly universal and portable means of storing comments inside pictures for the ultimate purpose of extracting with PHP to create web galleries.
T
toby
Feb 8, 2004
Paul Furman …
Toby Thain wrote:
/*
This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2002-4 Toby Thain,

Toby,

Do you know why photoshop uses IPTC format for this instead of exif or where the windows explorer properties are stored? I’m experimenting with using the jpeg comments header instead and I’m not sure which "standard" to adopt. Hmm, I guess that won’t work on tiff or psd though. I’m

Photoshop stores a block of image resources in those formats too. If you choose IPTC and embed in the same way as Photoshop, PS will be able to read your data as File Info, and can edit it and re-save in a compatible way too. This seems like a big plus.

wanting some fairly universal and portable means of storing comments inside pictures for the ultimate purpose of extracting with PHP to create web galleries.

OTOH, EXIF may be a little simpler. The code for working with this is already out there, I think.

T
PF
Paul Furman
Feb 9, 2004
Thanks!

I’ll ramble some more about what I’m doing…
<yawn>

I guess Irfanview will not destroy the IPTC but photoshop will destroy EXIF and only jpegs allow the EXIF comment header. If there was a command line operable IPTC utility, I could do that but I’m not much of a coder so this is the best I’ll do for now. Is there even a paid IPTC editor out there? I don’t even care if photoshop can read it, though that’s be nice, I’d not likely use PS to browse my collection anyways.

BTW, this is what I came up with in a couple days as a total beginner with PHP & I’m not much of a programmer:
< http://hills.ccsf.edu/~pfurma02/index.php?SCREEN=ecards.php& amp;IMG_DIR=cat&PAGE=2&PIC=7>
-just silly student stuff for now-

I used jhead command line exif editor to edit which requires using ascii files in the process so I kept those as my database since the school server doesn’t have the EXIF reading extension. I can only edit at home.

I’m still not clear about the windows explorer file properties.

I’m still not clear about if the exif editing does lossy compression on the jpegs.

Can a jpeg be given IPTC info without damaging it? I’ve mostly got digicam jegs.

Toby Thain wrote:

Paul Furman …

Toby Thain wrote:

/*
This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2002-4 Toby Thain,

Toby,

Do you know why photoshop uses IPTC format for this instead of exif or where the windows explorer properties are stored? I’m experimenting with using the jpeg comments header instead and I’m not sure which "standard" to adopt. Hmm, I guess that won’t work on tiff or psd though. I’m

Photoshop stores a block of image resources in those formats too. If you choose IPTC and embed in the same way as Photoshop, PS will be able to read your data as File Info, and can edit it and re-save in a compatible way too. This seems like a big plus.

wanting some fairly universal and portable means of storing comments inside pictures for the ultimate purpose of extracting with PHP to create web galleries.

OTOH, EXIF may be a little simpler. The code for working with this is already out there, I think.

T
T
toby
Feb 9, 2004
Paul Furman …
Thanks!

I’ll ramble some more about what I’m doing…
<yawn>

I guess Irfanview will not destroy the IPTC but photoshop will destroy EXIF and only jpegs allow the EXIF comment header. If there was a command line operable IPTC utility, I could do that …
I don’t even care if photoshop can read it, though
that’s be nice, I’d not likely use PS to browse my collection anyways.

The OP does, though.


Can a jpeg be given IPTC info without damaging it? I’ve mostly got digicam jegs.

I outlined the Photoshop-compatible way of doing this, above.

T

Toby Thain wrote:

Paul Furman …

Toby Thain wrote:

/*
This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2002-4 Toby Thain,

Toby,

Do you know why photoshop uses IPTC format for this instead of exif or where the windows explorer properties are stored? I’m experimenting with using the jpeg comments header instead and I’m not sure which "standard" to adopt. Hmm, I guess that won’t work on tiff or psd though. I’m

Photoshop stores a block of image resources in those formats too. If you choose IPTC and embed in the same way as Photoshop, PS will be able to read your data as File Info, and can edit it and re-save in a compatible way too. This seems like a big plus.

wanting some fairly universal and portable means of storing comments inside pictures for the ultimate purpose of extracting with PHP to create web galleries.

OTOH, EXIF may be a little simpler. The code for working with this is already out there, I think.

T

MacBook Pro 16” Mockups 🔥

– in 4 materials (clay versions included)

– 12 scenes

– 48 MacBook Pro 16″ mockups

– 6000 x 4500 px

Related Discussion Topics

Nice and short text about related topics in discussion sections