In the next article we are going to take a look at ExifTool. This is a free and open source program for reading, writing and manipulating image, audio, video and PDF metadata. It is independent of the platform we use. It is available as a Perl library and a command line application.
The metadata of the photographs is extra data that is added to the files. Such as the camera with which a photograph was taken or the time it was taken. These types of image metadata can be in various formats. The information that is housed in the metadata can be of any type, from the name of the company, to the name of the computer, through tags, modification dates, location, etc ...
ExifTool supports many different metadata formats including EXIF, GPS, IPTC, XMP, JFIF, GeoTIFF, ICC Profile, Photoshop IRB, FlashPix, AFCP, and ID3, as well as digital camera image metadata. As you can appreciate metadata isn't just for images, but can be applied to all types of files.
Although these details can be very useful to classify any type of file, they also may contain sensitive information. So we will also have to be careful about the files we share because they can carry information that we do not want to share.
ExifTool Installation
We can install ExifTool in Ubuntu in a simple way. We just have to open a terminal (Ctrl + Alt + T) and execute the following command:
sudo apt install libimage-exiftool-perl
With this we will have the program installed. Now we can work with it through the console.
Using metadata with ExifTool
Some of the main commands that the program accepts are the following:
The following command will show us all the metadata associated with the image that we indicate.
exiftool imagen.jpg
This command that follows will remove all the extra metadata associated with the file.
exiftool -all= imagen.jpg
The following command assigns a value to a TAG in the specified GROUP.
exiftool -[GROUP:]TAG=VALUE imagen.jpg
With these commands we could now manage all the metadata of the images. If you want to know more about the tags and groups available to manage them as each one wants, you can obtain more information in this web page. Another way of seeing more options of the exiftool command will be using the help of man in our operating system.
More examples for managing metadata
Next we are going to see some examples to see how to manage the metadata:
To add or modify GPS coordinates to a photograph, we would have to write something like the following:
exiftool -exif:gpslatitude="27 33" -exif:gpslatituderef=S -exif:gpslongitude="165 130" -exif:gpslongituderef=E fotografia.jpg
Conditional tagging with the -if option. This means that you can modify a series of metadata if it meets a condition, for example:
exiftool -alldates+=1 -if '$CreateDate ge "2017:11:02"' DIRECTORIO-IMAGENES
It will modify the time of the images in DIRECTORY-IMAGES. To these, 1 hour will be added if they were created after November 2, 2017, and only to those images. The -alldates option is an alias for all the timestamps that you can find in a jpeg file (Datetimeoriginal, CreateDate, and ModifyDate). You can learn about these and other exiftool options at this page.
The -if condition is generic, that means you can use it however you like as long as the Perl syntax is respected. You can concatenate multiple expressions with -if in a call to exiftool if necessary. Remember that the names of the labels within the condition must have the prefix "$", like the variables in perl. Who needs it will be able to find more examples and ideas in this website.
Another great thing about Exiftool is that you don't have to rewrite the EXIF metadata of an image. The -TagsFromFile option copies all the tags from the specified file to the file given as the final argument. For example:
exiftool -TagsFromFile tagged-img-fuente.jpg untagged-img-destino.jpg
The -w option on the other hand writes the EXIF data found in an image to a text file. If you add -htmlDump then it will write them to an HTML file. If what you need is to export all the metadata to a database, the best way to do it would be with the following command:
exiftool -t -S IMG-DIRECTORIO | grep -v ^====> img-tags-valores.txt
You can find another example of how it is done in this link.
Uninstall exiftool
To eliminate this program from our operating system we will only have to open a terminal (Ctrl + Alt + T). In it we will write the following order:
sudo apt remove libimage-exiftool-perl && sudo apt autoremove
Hello, that appears in terminal.
exiftool - [GROUP:] TAG = VALUE parrot.jpg
Warning: Tag '] TAG' does not exist
Nothing to do.
When trying to recover exif
exiftool -TagsFromFile tagged-img-20180625_0032.CR2 untagged-img-parrot.jpg
File 'tagged-img-20180625_0032.CR2' does not exist for -tagsFromFile option