/ ubuntu

Scrub Metadata From Stock Photos In Ubuntu

Disclaimer!

Don't steal images, but if you have stock photos with a bunch of metadata you don't want, there is an easy way to accomplish this using the command line.

To start we need to develop a workflow for doing this on a consistent basis, so let's set up our environment to enable us to easily accomplish this on a regular basis.

Our Process
'tokenname': {
	pattern: /regex/
}

Let's assume we have an image such as this

Now this is a .png image so we will need to write two scripts to handle .jpg images as well. However, before we do any of that, let's get the software we need to execute this task easily.

Open up a terminal window and enter the following

sudo apt-get install libimage-exiftool-perl

Ok that will install the exiftool command we need to write our scripts that will take care of our images.

Next, let's write our scripts.

In a Terminal window run the nano scrubjpg command. This will open up the text editor nano so that we can write our bash scripts.

Let's start with .jpg files. Copy and paste the following into your Terminal window. If you don't know how to paste into Terminal, you can simply right click on your mouse and hit "Paste" or you can use your keyboard by hitting Ctrl +Shift + V at the same time. I prefer the keyboard, it ends up being faster.

So, copy and paste this

#! /bin/bash

exiftool -all= *.jpg

echo jpg files successfully scrubbed!

exit

Now we need to save this file. In nano, to save a file you hit Ctrl + O then Enter. Now to exit nano hit Ctrl + X then Enter. Ok we now have a file called scrubjpg saved in whatever directory we were working in. This is great but it doesn't do us much good now. We need to stay in that directory and run chmod +x scrubjpg to make this file executable so it will run like a program. If you haven't already set up a bin directory in your home folder do it now. If you have ignore this step.

Run mkdir ~/bin. Awesome, but our system doesn't know that we want this directory added to our $PATH variable. So using nano again inside a Terminal window run nano ~/.bashrc.

Scroll down to the end of that file and add the line export PATH="$PATH:/home/replacewithyourusername/bin"

To get this to register in your current Terminal session run exec $SHELL -l (I don't feel like explaining this). Now we have a bin directory in our home folder and it is added to our $PATH. Awesome. We still haven't moved our scrubjpg script to our bin so it isn't doing us much good. Let's do that now. Assuming we are in the same directory as our script simply type mv ./scrubjpg ~/bin then hit Enter. Now if you type scrubjpg in a directory filled with .jpg files you will scrub the meta data and also create files with the same name + "_original" tagged at the end. These original files are the files you started with and contain all the metadata that they had before you scrubbed them. Do whatever you like with them. I don't care.

PNG Files

The process is the same

nano scrubpng

#! /bin/bash

exiftool -all= *.png

echo png files successfully scrubbed!  

exit


Save the file and run chmod +x scrubpng && mv scrubpng ~/bin

Now you have the command scrubpng to scrub the metadata from all your png files.

This is very easy and requires a very limited knowledge of the command line, but a very useful way to get rid of unwanted metadata using a simple Ubuntu tool.