Canon EOS camera

Managing WhatsApp photos using the exiftool

I tried to leverage the exiftool to help me manage my photo library, especially my received WhatsApp image files. These image files are quite heavily, lossy, compressed when sent and stripped of nearly all useful data, including the date when the photo was taken.

Fortunately, the file name contains a date token in it, which I can use. Here’s how:

Install the exiftool

The exiftool is a quite compreshensive and versatile image metadata processor, written in the Perl language by Phil Harvey. On Ubuntu 18.04, a package is already available:

sudo apt  install libimage-exiftool-perl

On other platforms, just follow the installation guide. Remember also, that there are platform specific requirements for quotes on options.

The following example commands all use a specific set of options. With this, changes are only for WhatsApp images (matched by a regex pattern), delivered in-place, recursively in the current and all it’s subdirectories, on all JPEG files. However, the @eaDir thumbnail image subdirectories are skiped. With -v, the output is verbose, which helps you monitor progress. Also, consider the fast option.

...  -overwrite_original -v -r -i '@eaDir' -ext JPG .

Tagging WhatsApp images

To simplify further processing and filtering by photo album software, I tagged all WhatsApp images with a keyword:

# For all WhatsApp JPEG images (matching the pattern 'IMG-YYYYMMDD-WANNNNNN.JPG')
# Add a 'WhatsApp' keyword, but only if:
# The keywords tag does not exist at all or
# The keywords do not contain 'WhatsApp' (case-insensitive)
exiftool -if '$filename=~/^IMG-\d{8}-WA\d{4}\.\w*/' -if 'not defined $Keywords or $Keywords!~/WhatsApp/i' '-Keywords+=WhatsApp' -overwrite_original -v -r -i '@eaDir' -ext JPG . -fast2

Set the EXIF date(s) from the filename

# For WhatsApp images (matching the pattern 'IMG-YYYYMMDD-WANNNNNN.JPG')
# Use the date/time information from the filename (e.g. YYYYMMDD). Note: This works by applying some cleverness by exiftool. The WA-part will get converted in minutes though.
exiftool -if '$filename =~ /^IMG-\d{8}-WA\d{4}\.\w*/' '-alldates<filename' -overwrite_original -v -r -i '@eaDir' -ext JPG . -fast2

This used the filename’s encoded date and applies it to all date/time tags in the metadata.

Set the file modification date from the EXIF date

Now, since those files have been modified along this process, the modification date might indicate a wrong date for indexing the file content on the Synology NAS:

# Use the extracted date information to rewrite the file modification date. This allows for proper indexing with the Synology NAS
exiftool -if '$filename =~ /^IMG-\d{8}-WA\d{4}\.\w*/' '-FileModifyDate<DateTimeOriginal' -overwrite_original -v -r -i '@eaDir' -ext JPG . -fast2