I like to illustrate my blog posts with my own photos, especially for my recipes. However, my phone is storing a lot of information in the EXIF metadata of the photos, such as my GPS location or the brand of my camera. This information is then visible by anyone who downloads a picture and checks its properties.

I don’t want this data to be published on my website, so here is how to scrub the photos' metadata in the command line on Ubuntu. It is also a good opportunity to optimize the format and size of the images. I provide different commands and tools depending on what you want to achieve.

Just removing the metadata

All the images for my static website are stored in one directory. To juste erase the metadata, run the following:

exiftool -All= * -overwrite_original

You can install Exiftools with:

sudo apt-get install libimage-exiftool-perl

Lossless optimization and metadata scrubbing

Additionaly, I convert JPEG images to progressive JPEG to improve the loading experience of my website without reducing the quality of images.

By default, JPEG images are loaded line by line. For high resolution images or slow connection speeds, this results in laggy white lines hiding the unloaded part of the picture.

Instead, progressive JPEG images are loaded by progressively increasing the resolution, resulting in a smoother experience. I run the following:

find . -name "*.jpg" -type f -exec jpegtran -copy none -optimize -progressive -outfile {} {} \;

The option -copy none removes metadata like above, but I found it more aggressive than Exiftools. For instance, it can remove the orientation of the photo if you rotated it with Google Photos.

You can install Jpegtran with:

sudo apt-get install libjpeg-progs

Image compression, optimization and metadata scrubbing

You might also want to reduce the quality of heavy images. This command does that, in addition to converting to progressive JPEG and scrubbing the metadata:

jpegoptim -m 80 -s --all-progressive *.jpg   

-m is a quality parameter between 0 and 100. There is also a --size option, but I found that sometimes it was reducing the quality more than what I asked for.

You can install Jpegoptim with:

sudo apt-get install jpegoptim