Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java code to write IPTC data to JPG in PhotoShop format

0 views
Skip to first unread message

Bob

unread,
Feb 7, 2004, 6:25:29 AM2/7/04
to
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?


Bob

unread,
Feb 7, 2004, 6:26:30 AM2/7/04
to

mscir

unread,
Feb 7, 2004, 4:00:45 PM2/7/04
to

Bob

unread,
Feb 7, 2004, 6:14:38 PM2/7/04
to
"mscir" <ms...@access4less.net> wrote in message
news:102akfv...@corp.supernews.com...

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).


mscir

unread,
Feb 7, 2004, 8:08:11 PM2/7/04
to

Sorry, I didn't interpret your original message correctly. Don't know
about writing to it.


Toby Thain

unread,
Feb 8, 2004, 1:04:30 AM2/8/04
to
"Bob" <ImageRead...@yahoo.com> wrote in message news:<1029klv...@corp.supernews.com>...

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, to...@telegraphics.com.au

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 */

Toby Thain

unread,
Feb 8, 2004, 5:41:10 AM2/8/04
to
to...@telegraphics.com.au (Toby Thain) wrote in message news:<d6ce4a6c.04020...@posting.google.com>...

> "Bob" <ImageRead...@yahoo.com> wrote in message news:<1029klv...@corp.supernews.com>...
> > 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

Paul Furman

unread,
Feb 8, 2004, 10:51:54 AM2/8/04
to
Toby Thain wrote:
> /*
> This file is part of DITABIS, a File Format plugin for Adobe Photoshop
> Copyright (C) 2002-4 Toby Thain, to...@telegraphics.com.au

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.

Toby Thain

unread,
Feb 8, 2004, 4:33:24 PM2/8/04
to
Paul Furman <pa...@edgehill.net> wrote in message news:<cL6dne3gPI9...@speakeasy.net>...

> Toby Thain wrote:
> > /*
> > This file is part of DITABIS, a File Format plugin for Adobe Photoshop
> > Copyright (C) 2002-4 Toby Thain, to...@telegraphics.com.au
>
> 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

Paul Furman

unread,
Feb 8, 2004, 9:09:22 PM2/8/04
to
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&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

unread,
Feb 9, 2004, 5:11:52 AM2/9/04
to
Paul Furman <pa...@edgehill.net> wrote in message news:<98ecnU6vNLs...@speakeasy.net>...

> 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

0 new messages