Just looked this up. Figure I'd share it here for future reference.
5 Answers
Install exiftool:
sudo apt-get install libimage-exiftool-perl
To read photo metadata:
exiftool /tmp/my_photo.jpg
To erase photo metadata:
exiftool -all= /tmp/my_photo.jpg
Before:
ExifTool Version Number : 8.60
File Name : my_photo.jpg
Directory : /tmp
File Size : 3.0 MB
File Modification Date/Time : 2013:02:24 12:08:10-08:00
File Permissions : rw-rw-r--
File Type : JPEG
MIME Type : image/jpeg
Exif Byte Order : Big-endian (Motorola, MM)
Orientation : Unknown (0)
Y Cb Cr Positioning : Centered
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Modify Date : 2013:02:24 11:25:27
Make : Samsung
Camera Model Name : Galaxy Nexus
Exif Version : 0220
Flashpix Version :
Color Space : sRGB
Components Configuration : Y, Cb, Cr, -
Compressed Bits Per Pixel : 0
Exif Image Width : 1944
Exif Image Height : 2592
Date/Time Original : 2013:02:24 11:25:27
Create Date : 2013:02:24 11:25:27
Exposure Time : 1/354
F Number : 2.8
Exposure Program : Aperture-priority AE
ISO : 50, 0, 0
Shutter Speed Value : 1/353
Aperture Value : 2.6
Brightness Value : 0
Exposure Compensation : 0
Max Aperture Value : 2.6
Subject Distance : 0 m
Metering Mode : Multi-spot
Light Source : Daylight
Flash : No Flash
Focal Length : 3.4 mm
Flash Energy : 0
Exposure Index : undef
Sensing Method : One-chip color area
Scene Type : Directly photographed
Custom Rendered : Custom
Exposure Mode : Auto
White Balance : Auto
Digital Zoom Ratio : 1
Scene Capture Type : Standard
Contrast : Normal
Saturation : Normal
Sharpness : Normal
Subject Distance Range : Unknown
Image Unique ID : OAEL01
GPS Time Stamp : 19:25:27
GPS Date Stamp : 2013:02:24
Compression : JPEG (old-style)
Thumbnail Offset : 2143
Thumbnail Length : 10941
Image Width : 1944
Image Height : 2592
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Aperture : 2.8
GPS Date/Time : 2013:02:24 19:25:27Z
Image Size : 1944x2592
Shutter Speed : 1/354
Thumbnail Image : (Binary data 10941 bytes, use -b option to extract)
Focal Length : 3.4 mm
Light Value : 12.4
After:
ExifTool Version Number : 8.60
File Name : my_photo.jpg
Directory : /tmp
File Size : 2.9 MB
File Modification Date/Time : 2013:02:24 12:21:39-08:00
File Permissions : rw-rw-r--
File Type : JPEG
MIME Type : image/jpeg
Image Width : 1944
Image Height : 2592
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Image Size : 1944x2592
References:
-
1To process all files in the current directory:
for f in *.jpg; do exiftool -all= "$f"; done
– twobeersJun 23, 2014 at 9:38 -
9
-
2You probably don't want to delete all EXIF metadata. For example, the "Orientation" piece of metadata rotates the photo. If you remove it, then the photos will appear to be rotated in the wrong way.– FlimmAug 23, 2021 at 14:20
-
@pablo-bianchi I reverted your edit because security vulnerability info isn't really relevant to the question and somewhat ephemeral. Here's the link to the CVE alert that was removed: ubuntu.com/security/CVE-2021-22204– klenwellSep 25, 2021 at 19:48
Imagemagick
Instead of Exiftool, to handle Exif metadata (IPTC, XMP and ICC image metadata also) I found Imagemagick more useful and command easier to remember.
Since IMv7 magick identify/mogrify/...
it's used instead [1].
To read
identify -verbose image.jpg | grep exif
To remove
With imagemagick
package installed you can do this (not only for JPEGs):
mogrify -strip *.jpg # Optionally: -verbose
From manual:
-strip
strip the image of any profiles, comments or these PNG chunks: bKGD, cHRM, EXIF, gAMA, iCCP, iTXt, sRGB, tEXt, zCCP, zTXt, date.
Since you will lose the orientation metadata, maybe you'll want to mogrify -auto-orient image.jpg
first.
AFAIK the only difference with exiftool is that mogrify
won't remove this metadata:
- JFIF Version
- Resolution Unit
- X Resolution
- Y Resolution
Which might be useful. Compared with diff -y <(exiftool wMogrify.jpg) <(exiftool wExiftool.jpg)
Remove EXIF data is not the same as anonymize: -strip
will recompress the image. This might be a good thing: The same software that take the photo (or other) could hide sensitive information (which may be encrypted) inside of ordinary image data (steganography). I'm not sure if the recompression will always remove everything (probably not). To avoid this recompression you can use jpegtran:
jpegtran -copy none image.jpg > newimage.jpg
Also, to avoid losing color profile (ICC metadata, which causes richer colors[citation needed]):
convert image.jpg profile.icm && convert image.jpg -strip -profile profile.icm newimage.jpg
You might ask yourself if these costs are noticeable or relevant in your case.
Another tool about steganography on images is steghide.
Other tools and notes
- mat2 (Metadata anonymization toolkit v2): Removes metadata from a lot of formats (
--list
). It's recommended by privacyguides.org. - Alternatives:
jhead
(only for JPEGs) and exiv2 (man; suggested on Wikipedia). - Metadata Cleaner: Desktop app to view and clean metadata in files (not only images).
- If you prefer Exiftool, you might find useful creating an alias to
exiftool -all= *.jpg && rm *original
, or with-overwrite_original
option. To remove only GPS data useexiftool -gps:all= -xmp:geotag= *.jpg
. Use an updated version: CVE-2021-22204. - WebP format:
webp
package provideswebpmux
command, which manage XMP/EXIF metadata and ICC profile.
See also
-
1Note however that this appears to recompress the image: stackoverflow.com/questions/2654281/… Sep 6, 2019 at 21:44
-
1@CiroSantilli新疆改造中心996ICU六四事件I edited the answer. That' might be a good thing, to remove metadata encoded on the image. Would be great to have studies to support this. Sep 21, 2019 at 18:05
-
Yes, I noticed this because the image size had changed considerably, but there must be better ways, at least in 2010 ImageMagick devs confirmed it: stackoverflow.com/questions/2654281/… Sep 21, 2019 at 19:01
-
1Note that
mogrify -strip *.jpg
does remove the "Orientation" piece of metadata. Photos may appear to be rotated the wrong way without this piece of metadata. Same thing forjpegtran -copy none example.jpg > out.jpg
– FlimmAug 23, 2021 at 14:23
To remove then change a single field we can use this command:
exiftool -Copyright= IMG_3357.jpg
exiftool -Copyright=LinuxSlaves IMG_3357.jpg
I wish to add mat2
which support not only images. It's recommended by privacyguides.org (formerly known as privacytools.io) community.
MAT2 is free software, which allows the removal of metadata of image, audio, torrent, and document file types. It provides both a command line tool and a graphical user interface via an extension for Nautilus, the default file manager of GNOME.
and
mat2 is a metadata removal tool, supporting a wide range of commonly used file formats, written in python3: at its core, it's a library, used by an eponymous command-line interface, as well as several file manager extensions.
sudo apt install mat2
in-place purge of metadata
mat2 --inplace xxx.mp4
mat2 --inplace xxx.png
There are a number of tools for this, as others have listed. One more that I found on my system is exiv2
.
Install: sudo apt-get install exiv2
View: exiv2 myimage.jpg
Remove: exiv2 rm myimage.jpg
Additional options are listed in the man page.
-
Note that
exiv2 rm myimage.jpg
seems to remove the "orientation" metadata. This will make the resulting image appear to be rotated the wrong way in some cases.– FlimmAug 23, 2021 at 14:25
sudo apt-get install exiv2
and thenexiv2 rm *.jpg