10

I'm trying to remove metadata from a .jpg file and replace it with nothing. Can anyone provide an example of how I might do this?

Samir
  • 103
  • 1
  • 6
  • Related: http://stackoverflow.com/questions/37062959/how-to-remove-image-metadata-from-large-images-without-out-of-memory-in-java – Thilo May 06 '16 at 01:55

2 Answers2

10

Metadata isn't read when you read in the image. So just read it in and write it back.

BufferedImage image = ImageIO.read(new File("image.jpg"));
ImageIO.write(image, "jpg", new File("image.jpg"));
tskuzzy
  • 35,812
  • 14
  • 73
  • 140
  • 1
    That is the whole program. Just replace "image.jpg" with the file name. – tskuzzy Jul 12 '11 at 17:19
  • 1
    What about keep the image quality? – StanislavL Jul 13 '11 at 07:32
  • 3
    Oh, I totally forgot about lossy compression... That's a great point. Perhaps this is a little more difficult than at first glance. I think you might be stuck with reading in the image as a byte stream and manually stripping the metadata... – tskuzzy Jul 13 '11 at 11:38
3

The Apache ExifRewriter:

Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.

FileInputStream is = new FileInputStream(new File("/path/to/photo.jpg"));
FileOutputStream os = new FileOutputStream(new File("/path/to/photo_without.jpg"))) 

new ExifRewriter().removeExifMetadata(is, os);
clic
  • 365
  • 1
  • 13