Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove metadata from a JPEG image in Java?

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?

like image 795
Samir Avatar asked Jul 12 '11 15:07

Samir


2 Answers

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"));
like image 173
tskuzzy Avatar answered Sep 22 '22 14:09

tskuzzy


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);
like image 42
clic Avatar answered Sep 21 '22 14:09

clic