I Found The One Tool To Sort All Your Pictures Like A Boss

Written by tristanry | Published 2020/05/01
Tech Story Tags: exiftool | photography | sorting | bash | image-processing | image | latest-tech-stories | how-to-use-exiftool-for-images

TLDR The ExifTool is a Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files. The solution should be viewer agnostic, i.e. i should be able to see my photos sorted directly in a folder using Nautilus or Finder. To sort my pictures, I am using the following metadata:Custom tag to separate dedicated photo sessions, e.g. a trip in Italy or a trip abroad. I have incorporated that into a bash script: sh tagImportedImages.sh.via the TL;DR App

For years I have been frustrated and I wanted to find a proper way of sorting my pictures. I had photos coming from several devices, and made manual copies on my laptop and on my external hard drive. I ended up with tons of folders and a lot of duplicates.

Back then, I only used Ubuntu and its default photo manager Shotwell.It was pretty handy, but images of my travels were mixed with my casual smartphone pictures. The worst part was the fact that all my pictures were stored on a single folder per date. Then, I started to used Mac with its integrated tool Photos. Like Shotwell, the software is great, especially if you have Apple devices but everything is stored under one giant photoslibrary archive.
Based on all these observations, I started to look for a simple and universal way to sort all my previous and future pictures.

Requirements

The solution should:
  • Work on different OS, Linux, OSX, (Windows)
  • Be viewer agnostic, i.e. i should be able to see my photos sorted directly in a folder using Nautilus or Finder
  • Accept all devices and image formats
  • Require few manual intervention
  • Be reproducible: if I sort my gallery again, I should get the same result

Solution

In order to achieve that, I used a ExifTool which is a “platform-independent Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files”.
To sort my pictures, I am using the following metadata:
  • Custom tag to separate dedicated photo sessions, e.g. a trip in Italy
  • The camera name and model
  • The date
  • The type of file

Installation

Workflow

Tag events
Firstly, I wanted to highlight specific events such as a trip abroad and at the
same time be sure that my sorting was reproducible. To do that, I had to add a metadata information at the photo level.
When you look at the metadata stored in Exchangeable image file format (Exif) there are tens of attributes. By default the UserComment field is not filled, therefore I used this attribute to store my event:
You can write/overwrite the UserComment field via exiftool. By convenience I have incorporated that into a bash script:
#!/bin/bash
## PATH TO MY IMAGES DIRECTORY ##
DEFAULTIMPORTED=/tmp/Images/0_Imported/ #Images to be imported

## USER COMMENT AS A PARAMETER#
TRAVEL=$1

## METADATA WRITING ##
if [ $# -eq 1 ]; then
  IMPORTED=$DEFAULTIMPORTED
  exiftool -UserComment=$TRAVEL $IMPORTED  -overwrite_original 
elif [ $# -eq 2 ]; then
  IMPORTED=$2
  exiftool -UserComment=$TRAVEL $IMPORTED  -overwrite_original 
else
   echo "USAGE: sh tagImportedImages.sh USERCOMMENT [DIRECTORY]"
fi
You can verify the UserComment field as follow:
Sort
Once all specific events are filled at the photo level, I can sort all my images using Exiftool again.
I have decided to use the following logic, but feel free to change it to your convenience:
Here is the script corresponding to the rules above:

#!/bin/bash
## PATH TO MY IMAGES DIRECTORY ##
IMPORTED=/tmp/Images/0_Imported/ #Images to be imported
GALLERY=/tmp/Images/1_Gallery/ #Gallery folder

## SORTING IMAGE COMMAND ##
exiftool -d $GALLERY"%Y/" -r $IMPORTED \
'-Directory<${FileModifyDate}IMAGES' \
'-Directory<${CreateDate}${FileType}' \
'-Directory<${datetimeoriginal}${make}-${model;}_ALL' \
'-Directory<${datetimeoriginal}${make}-${model;}_${UserComment}'

## DELETE REMANING EMPTY FOLDERS ##
find $IMPORTED -type d -empty -delete -mindepth 1
Exiftoll command details:
  • -d: used to indicate that we will sort the images by date. Here we have
    chosen one folder per year %Y. You can easily decide to have one folder
    per month using %Y%M or %Y/%M.
  • $GALLERY”%Y/: destination of the images
  • $IMPORTED: sources of the images
  • -r: means that the sorting will be effective recursively on your target folder and all the associated subfolders
The script presented above will sort all the images in the IMPORTED folder
and move them to the GALLERY folder. If you try to import images already
present in the GALLERY, they will stay in the IMPORTED folder. This means that all remaining images in GALLERY are duplicates based on the UserComment, and camera, and date and filename.
With the option -o you can sort all the images in the IMPORTED folder and copy them to the GALLERY folder.

Recap

Exiftool offers the possibility to consistently sort all my pictures coming from several devices on all the platforms. The tool is also very flexible
and quick. It took 20 minutes to sort 50 GB of photos. Now, I can view
all my photos directly in the default file manager or via gallery
softwares that are reusing the folder structure such as gThumb or Luminar.
(Featured Image by Vladyslav Dukhin from Pexels)

Published by HackerNoon on 2020/05/01