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?
Asked
Active
Viewed 9,969 times
2 Answers
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
-
1That is the whole program. Just replace "image.jpg" with the file name. – tskuzzy Jul 12 '11 at 17:19
-
1
-
3Oh, 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