Skip to main content

Read and write EXIF tags from Jpeg

11 replies [Last post]
Anonymous

Hi,

We are desperately looking for open source libraries to read and write (compressed?) EXIF tags from a Jpeg file.

We 'simply' want to read the capture date of a digital photo and write it's location into the geo tags (lat/lon).

We already found http://drewnoakes.com/code/exif/ but did'nt succeed. And googling it mostly leads to Imagero and reading with no writing code.

Any hints are welcome.
-- Geonick

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23
Points: 0

One further comment on this. If you use the Image I/O libraries and do a read and write then you will suffer data loss during the JPEG decoding and re-encoding. So to insert the geolocation data you will likely have to write some special software. As mentioned, the read part can be done with the extant plug-ins.

Brian

> Hi,
>
> We are desperately looking for open source libraries
> to read and write (compressed?) EXIF tags from a Jpeg
> file.
>
> We 'simply' want to read the capture date of a
> digital photo and write it's location into the geo
> tags (lat/lon).
>
> We already found http://drewnoakes.com/code/exif/ but
> did'nt succeed. And googling it mostly leads to
> Imagero and reading with no writing code.
>
> Any hints are welcome.
> -- Geonick

vinoth_vvv
Offline
Joined: 2006-02-17
Points: 0

Many thanks for all tips including some mails from the MediaUtil author! I have to admit that we are a little bit confused... Apparently this exercise becomes really a heavy weight endeavour. But we'll dig through.

Here again what our requirements are:
* 100% Java, open source, standards (library) based
* JPEG; changing header only (in place editing)
* No data loss of either header (other metadata incl. thumbnail) nor content
* Reading out capture time
* Reading out GPS coordinates (lat/lon) and altitude
* Writing back GPS coordinates and altitude
* Delivered as command line tool, i.e. as light weight as possible (perhaps later we'll add a GUI frontend).

-- Geonick

Message was edited by: geonick (typos)

Message was edited by: geonick

Brian Burkhalter

On Sat, 4 Feb 2006, jai-imageio@javadesktop.org wrote:

> Many thanks for all tips including some mails from the MediaUtil author! I have to admit that we are a little bit confused... apperently this exercise becomes really a heavy weight endeavour. But we'll dig through.
>
> Here again what our requirements are:
> * 100% Java, open source, standards (library) based
> * JPEG; changing header only (in place editing)

Perhaps someone will correct me on this point, but I don't think it is
possible to do in place editing on a JPEG file if involves changing the size
of a marker segment, i.e., inserting new information is not possible. I think
what you have to do to solve your problem is to break the image up into
separate marker segments, modify the APP1 EXIF marker as described below, and
then reassemble the marker segments into a new JPEG stream.

Brian

> * No data loss of either header (other metadata incl. thumbnail) nor content
> * Reading out capture time GPS coordinates
> * Writing back GPS coordinates latitude, longitude and altitude
> * Command line tool, i.e. as light weight as possible (perhaps later we'll add a GUI frontend).
>
> -- Geonick
> [Message sent by forum member 'geonick' (geonick)]
>
> http://forums.java.net/jive/thread.jspa?messageID=78935
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Brian Burkhalter

We have been hoping to address this issue more completely in JAI-Image I/O
Tools. I think that actually all of the reading capability already exists if
you use the Java SE Image I/O JPEG reader to get the metadata, extract the
EXIF marker segment contents, and use the JAI-Image I/O TIFF reader to read
the fields. As for writing capability, the Java SE Image I/O JPEG writer can
write the metadata when supplied with the marker segment, but the JAI-Image
I/O TIFF writer will not create an empty image, i.e., one with metadata but
no image. This is the subject of this bug:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6194442

Brian

On Sun, 29 Jan 2006, jai-imageio@javadesktop.org wrote:

> Hi,
>
> We are desperately looking for open source libraries to read and write (compressed?) EXIF tags from a Jpeg file.
>
> We 'simply' want to read the capture date of a digital photo and write it's location into the geo tags (lat/lon).
>
> We already found http://drewnoakes.com/code/exif/ but did'nt succeed. And googling it mostly leads to Imagero and reading with no writing code.
>
> Any hints are welcome.
> -- Geonick
> ---
> [Message sent by forum member 'Geonick' (Stefan F. Keller)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=141510
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Anonymous

Many thanks to Brian and Richard for your answers.

Because I'm new in JPeg metadata reading this confuses me: You write "I think that actually all of the reading capability already exists if you use the Java SE Image I/O JPEG reader to get the metadata, extract the EXIF marker segment contents, and use the JAI-Image I/O TIFF reader to read the fields".
=> So are you saying: For reading JPeg EXIF metadata I have a) to use both "Image I/O JPEG reader" as well as "JAI-Image I/O TIFF reader"?
=> For writing JPeg EXIF metadata, I could use "Image I/O JPEG writer" for the metadata and "JAI-Image I/O TIFF writer" for the image body but the latter will not work?

First: Why a "TIFF writer" when there is a JPeg?
Second: Can this bug be prevented? E.g. by writing the header straight back into the source JPeg image?

-- Geonick

Brian Burkhalter

nOn Mon, 30 Jan 2006, jai-imageio@javadesktop.org wrote:

> Many thanks to Brian and Richard for your answers.
>
> Because I'm new in JPeg metadata reading this confuses me: You write "I think that actually all of the reading capability already exists if you use the Java SE Image I/O JPEG reader to get the metadata, extract the EXIF marker segment contents, and use the JAI-Image I/O TIFF reader to read the fields".
> => So are you saying: For reading JPeg EXIF metadata I have a) to use both "Image I/O JPEG reader" as well as "JAI-Image I/O TIFF reader"?

Yes. The EXIF metadata is stored using the TIFF Image File Directory (IFD)
even when it is in a JPEG file. In that case it is found in an APP1marker
segment. You can use the Java SE Image I/O JPEG reader plug-in to get the APP1
marker segment from an "unknown" marker segment as described here

http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/metadata/doc-files...

If you then load the portion of the APP1 segment after the EXIF identifier
code into an ImageInputStream then you should be able to use the TIFF reader
plug-in to read the metadata into a DOM tree in either the TIFF native image
metadata format or in the standard metadata format.

If you load the APP1 marker segments

> => For writing JPeg EXIF metadata, I could use "Image I/O JPEG writer" for the metadata and "JAI-Image I/O TIFF writer" for the image body but the latter will not work?

If the TIFF writer supported creating a TIFF stream without images then you
could essentially reverse the process described above. You would in this case
use the TIFF writer to create the APP1 marker segment contents which would
then be passed via an "unknown" marker segment node to the Java SE Image I/O
JPEG writer.

> First: Why a "TIFF writer" when there is a JPeg?

As stated, although the overall image stream might be a JPEG the APP1 metadata
actually uses the TIFF structure.

> Second: Can this bug be prevented? E.g. by writing the header straight back into the source JPeg image?

If your manipulation of the metadata is simple as it sounds like it is, you
could probably just manipulate the TIFF IFD from the APP1 marker using
specialized code and you wouldn't even need the TIFF plug-ins. I only
mentioned these to address the general case. For a simple, specific
manipulation you should be able to use the Java SE Image I/O JPEG plug-ins
with specialized code to manipulate the APP1 contents.

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Anonymous

Thanks to Brian (and of course also to Andrey for his former post). For the understanding explaining the general case was very instructive.

In our case its really as simple as 1. reading the 'date captured' out of a JPEG, then 2. writing lat/lon coordinates into the EXIF metadata. Later on, perhaps reading lat/lon before writing somethin back would be a plus - that's all!

What we have in mind is doing simple geotagging as a postprocess by adding location information from GPS (or other) tracks being collected around the same time the picture was taken (perhaps flickr can utilize it in the near future?). And I wonder whether we are really pioneers doing that in Java...!?
-- Geonick

Message was edited by: Geonick

Brian Burkhalter

As mentioned in my previous post, you should be able to accomplish step 1,
reading the date captured, using existing interfaces. Step 2 however would on
second thought be tricky to accomplish by just tweaking the IFDs in the APP1
marker segment. The problem is that these IFD include offset information
which would need to be updated to reflect the insertion of the position data.
Specifically you would need to update the offset to the 1st IFD (thumbnail),
which is stored at the end of the 0th IFD, as well as the value of the
JPEGInterchangeFormat field in the 1st IFD. These would need to be
incremented by the extra amount of space required for the terrestrial
coordinate information.

Brian

On Tue, 31 Jan 2006, jai-imageio@javadesktop.org wrote:

> Thanks to Brian (and of course also to Andrey for his former post). For the understanding explaining the general case was very instructive.
>
> In our case its really as simple as 1. reading the 'date captured' out of a JPEG, then 2. writing lat/lon coordinates into the EXIF metadata. Later on, perhaps reading lat/lon before writing somethin back would be a plus - that's all!
>
> What we have in mind is doing simple geotagging as a postprocess by adding location information from GPS (or other) tracks being collected around the same time the picture was taken (perhaps flickr can utilize it in the near future...)

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Andrey Kuznetsov

> We are desperately looking for open source libraries to read and write
> (compressed?) EXIF tags from a Jpeg file.
>
> We 'simply' want to read the capture date of a digital photo and write
> it's location into the geo tags (lat/lon).
>
> We already found http://drewnoakes.com/code/exif/ but did'nt succeed.
> And googling it mostly leads to Imagero and reading with no writing code.

with Imagero you can edit existing EXIF data.

And really I would like to make Imagero open source,
but before I have to win in lotto,
or someone may decide to funding my expenses,
or may be kommunism wins and everyone can take how
much he need and give how much he can
(take it easy - it was just a joke and sorry for probably horrible english).

--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Richard Smith

It sounds to me like http://sourceforge.net/projects/libexif meets the
stated
requirements.

--
============================================================================
,-_|\ Richard Smith - Technical Specialist
/ \ Sun Microsystems Australia Phone : +61 3 9869 6200
richard.smith@Sun.COM Direct : +61 3 9869 6224
\_,-._/ 476 St Kilda Road Fax : +61 3 9869 6290
v Melbourne Vic 3004 Australia
===========================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Andrey Kuznetsov

> It sounds to me like http://sourceforge.net/projects/libexif meets the
> stated requirements.

I would prefer exiftool http://www.sno.phy.queensu.ca/~phil/exiftool/

--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net