EXIF tag handling in Java

M

Martin Gregorie

Can anybody recommend a good EXIF tag handling Java package?

I need to use it for reading and writing 'Comment' tags in at least JPG
files, and preferably for more image types than just JPG. I found out, by
experimenting with exiftool, that both PNG and GIF files also support the
'Comment' tag.

I have found a couple of packages (Thang To's javaexif and Thomas Lane's
Mediautil package), both dating from 2006 or so and both largely
uncommented, which doesn't make them exactly easy to use.
 
M

Marty Blake

Can anybody recommend a good EXIF tag handling Java package?

Install Java ImageIO and the TIFF plugin for ImageIO and you can get at
(and modify) JPEG EXIF tags using ImageIO. I'm not sure about other
formats (except TIFF should work).
 
M

Martin Gregorie

Install Java ImageIO and the TIFF plugin for ImageIO and you can get at
(and modify) JPEG EXIF tags using ImageIO. I'm not sure about other
formats (except TIFF should work).
Thanks for that. It looks like all this is in the javax.imageio.*
packages.

I've had a look at the docs for these packages, including the plugins,
and frankly I'm baffled and/or confused. There are packages that define
the tags but nothing that I can find that can, for instance, read or
write tags from something like a BufferedImage. Is there a tutorial or
other how-to that covers classes that provide accesss to EXIF tags?
 
J

Jeff Higgins

Thanks for that. It looks like all this is in the javax.imageio.*
packages.

I've had a look at the docs for these packages, including the plugins,
and frankly I'm baffled and/or confused. There are packages that define
the tags but nothing that I can find that can, for instance, read or
write tags from something like a BufferedImage. Is there a tutorial or
other how-to that covers classes that provide accesss to EXIF tags?
This may help. May not too. Pretty old.
<http://www.barregren.se/blog/how-read-exif-and-iptc-java-image-i-o-api>
A possible bug.
<http://george.i.ph/blogs/george/200...-exif-using-the-javaximageiometadata-package/>
Links to the "standard" and "native" metadata formats.
<http://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/package-summary.html>
The parser library referenced in the first link above.
<http://code.google.com/p/metadata-extractor/>
 
M

Martin Gregorie

This may help. May not too. Pretty old.
<http://www.barregren.se/blog/how-read-exif-and-iptc-java-image-i-o-api>
A possible bug.
<http://george.i.ph/blogs/george/2007/09/06/read-and-write-jpeg-exif- using-the-javaximageiometadata-package/>
Links to the "standard" and "native" metadata formats.
<http://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/ package-summary.html>
The parser library referenced in the first link above.
<http://code.google.com/p/metadata-extractor/>

Thanks for those links. That Google parser is read-only, but its
documentation looks useful.

Just now I thought to look at Apache Commons and found the Sanselan
package, which does a similar job to the javax.imagio.* stuff but as a
free-standing package and, unlike them, it includes EXIF read/write
abilities.

Its interesting that all this stuff is about the same age: Java 1.4 or 5
and none of it seems to have been updated since. Maybe, since nothing has
changed in the JPEG/TIFF worlds since then it hasn't needed any updates,
though as its all decidedly light on documentation, some changes there
would be nice for those of us who don't understand the structure of image
files: another common thread in all these packages is that the authors
all appear to assume that everybody is an expert on image files and their
contents.
 
J

Jeff Higgins

Just now I thought to look at Apache Commons and found the Sanselan
package, which does a similar job to the javax.imagio.* stuff but as a
free-standing package and, unlike them, it includes EXIF read/write
abilities.
Great! Thanks for the tip.:)
 
M

Martin Gregorie

api>

Link to source broken, found a copyhere:
<http://files.codes-sources.com/fichier_fullscreen.aspx? id=35614&f=GestionDimagesNumeriques+[javaFR]\src\com\picturegrid\imageio
\metadata\ImageIOMetadataDemo.java>
A possible bug.
<http://george.i.ph/blogs/george/2007/09/06/read-and-write-jpeg-exif- using-the-javaximageiometadata-package/>

Links to the "standard" and "native" metadata formats.
<http://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/ package-summary.html>

The parser library referenced in the first link above.
<http://code.google.com/p/metadata-extractor/>

Thanks for the URL correction.
 
K

Knute Johnson

Can anybody recommend a good EXIF tag handling Java package?

I need to use it for reading and writing 'Comment' tags in at least JPG
files, and preferably for more image types than just JPG. I found out, by
experimenting with exiftool, that both PNG and GIF files also support the
'Comment' tag.

I have found a couple of packages (Thang To's javaexif and Thomas Lane's
Mediautil package), both dating from 2006 or so and both largely
uncommented, which doesn't make them exactly easy to use.

Martin:

There used to be a big JAI/ImageIO users list that I belonged to several
years ago. I don't know if JAI is still relevant but I would think that
would be a good place to look for EXIF info.

I found this website: http://java.net/projects/jai-imageio/.

Hope that helps.
 
J

John B. Matthews

Martin Gregorie said:
Can anybody recommend a good EXIF tag handling Java package?

I need to use it for reading and writing 'Comment' tags in at least
JPG files, and preferably for more image types than just JPG. I found
out, by experimenting with exiftool, that both PNG and GIF files also
support the 'Comment' tag.

I have found a couple of packages (Thang To's javaexif and Thomas
Lane's Mediautil package), both dating from 2006 or so and both
largely uncommented, which doesn't make them exactly easy to use.

For reference, ImageJ [1] includes the Exif_Reader [2] plugin, which is
based on Drew Noakes' Exif Metadata Library. The plugin is read-only,
but handy.

[1] <http://rsbweb.nih.gov/ij/>
[2] <http://rsbweb.nih.gov/ij/plugins/exif-reader.html>
[3] <http://www.drewnoakes.com/code/exif>
 
M

Martin Gregorie

Thanks to all of you who have responded. I should have enough information
now to be able to dig into the issue of adding comments to images in the
form of EXIF tags.

Perhaps I should explain what I'm doing. I have a Java program, run
overnight as a cron job, that can walk a directory tree and decorate it
with a thumbnail of every new or modified image it finds. As I run an in-
house webserver, this is enough to let a PHP script generate on-the-fly
menus from directories in the tree which contain clickable links to all
files in the directory. Links to images display the thumbnail as part of
that menu entry. However, this doesn't work if you simply point a browser
at a local copy of the directory structure, so the Java program can also
generate a linked set of static menus that work in the same way for
people who don't run a web server.

This is working reliably and well. It has met my design target of
automatically indexing sets of images as they are dropped on a hard drive
so they can be scrolled through using smaller images that those can be
selected so the full resolution image can be seen.

Now I'd like to display descriptions, when they are available, under the
thumbnails.

Thanks to all of you I now know that I can write a program to add the
descriptions to the images as EXIF 'Comment' tags and in parallel I've
checked that PHP can extract the content of those tags in order to add
them to the on-the-fly menus and that Java can do the same for the static
menus.

The only issue is speed: the PHP library routines to check that the image
is the right type to have EXIF tags and to extract the tags require each
image to be read several times: (1) to display the thumbnail, (2) to see
if it is the right type to hold tags [this can probably be skipped] and
(3) to extract the Comment tag's content. Currently only (1) happens, so
I need to benchmark things to see if the PHP script is fast enough to
support extracting captions from EXIF tags: this is not a consideration
for the Java menu builder since this is never run when a user wants to
see an list of images *right now*.

If the PHP menu generator is unacceptably slow when dealing with EXIF
tags, I'll use the aesthetically ugly trick of keeping the captions as a
separate CSV list (filename,caption) which will probably be faster since
at the start of the run it can be loaded into a Hashtable (Java) or
associative array (PHP) once and will stay in memory while the menu
builder is running.

Thanks again for your help.
 
L

Lew

Martin said:
If the PHP menu generator is unacceptably slow when dealing with EXIF
tags, I'll use the aesthetically ugly trick of keeping the captions as a
separate CSV list (filename,caption) which will probably be faster since
at the start of the run it can be loaded into a Hashtable (Java) or
associative array (PHP) once and will stay in memory while the menu
builder is running.

I recommend against use of 'java.util.Hashtable' in favor of the modern (since 1998) 'Map' implementations.
 
M

Martin Gregorie

I recommend against use of 'java.util.Hashtable' in favor of the modern
(since 1998) 'Map' implementations.
Thanks for that. My normal default is to use a TreeMap. It maybe a bit
slower, but its surprising how often the implied ordering turns out to be
useful, if only for debugging.

I've just upgraded my PHP on-the-fly menu generator to display EXIF
Copyright and Comment tags and given it a fairly thorough bashing. I've
run it against fairly large lists of images, up to 300 photos averaging
2.0 MB each, which don't yet contain either Copyright or Comment tags.
Menu generation is a little slower than before, but not enough to be a
show stopper, so I'll implement the bulk comment insertion program rather
than using an external comments list. Game on!
 
M

Martin Gregorie

I recommend against use of 'java.util.Hashtable' in favor of the modern
(since 1998) 'Map' implementations.

Noted. I only considered Hashtable because they are favoured by some of
the javax.imageio.* packages - scarecely surprising since most of these
packages seem to have been around since at least Java 1.4.
 
L

Lew

Noted. I only considered Hashtable because they are favoured by some of
the javax.imageio.* packages - scarecely surprising since most of these
packages seem to have been around since at least Java 1.4.

Very, very surprising since the modern collections classes were introduced in Java 1.2 and the javax.imageio package in Java 1.4.

You should check the Javadocs.
 
M

Martin Gregorie

Very, very surprising since the modern collections classes were
introduced in Java 1.2 and the javax.imageio package in Java 1.4.

You should check the Javadocs.

I did: for some operations you need to use a filter which is based
java.awt.image.ImageFilter. This gets passed properties via the
setProperties(Hashtable<?,?>) method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top