Dumping metadata with javax.imagio

B

Brian S O'Neill

Sometimes JPEG files, especially from digital cameras, have a bunch of
metadata. I'd like to read a JPEG file and write it back out, stripping
out this metadata.

The javax.imageio package provides nice methods for reading and writing
image files, but I cannot figure out a way to write the new JPEG out
without having to recompress and lose data. If the compression quality
is set to highest, does this preserve the original quality without
increasing file size?

Is there any special way to make javax.imageio support what I want, or
is there another API that can do this?
 
M

Marco Schmidt

Brian S O'Neill:
Sometimes JPEG files, especially from digital cameras, have a bunch of
metadata. I'd like to read a JPEG file and write it back out, stripping
out this metadata.

If it doesn't have to be Java try the jpegtran command line utility:

$ jpegtran -copy none input.jpg > output.jpg
The javax.imageio package provides nice methods for reading and writing
image files, but I cannot figure out a way to write the new JPEG out
without having to recompress and lose data. If the compression quality
is set to highest, does this preserve the original quality without
increasing file size?

If quality is set to highest you do lossy recompression, and you may
lose some more quality (but not much). File size will increase, though
(at least according to the test I just ran).
Is there any special way to make javax.imageio support what I want, or
is there another API that can do this?

I've listed some Java metadata libraries at
<http://www.geocities.com/marcoschmidt.geo/jpeg-image-file-format.html>.
But I don't think they can do what you ask for.

javax.imageio - I've yet to see some documentation on the metadata
part that explains (with code examples) what can be done with this
potentially powerful library. Sorry, can't help there.

Your best bet from within Java is probably running jpegtran with
Runtime.exec.

Regards,
Marco
 
B

Brian S O'Neill

The EXIF format used by many digital cameras supports rich metadata,
including audio samples. For a website that supports user image
submission, you might want to serve the main image, not hidden metadata.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top