1. Introduction
Pictures have primarily shifted to digital formats, with even printed photographs eventually being digitized. One of the most important components of digital image files is metadata, which gives significant information about the image’s qualities and origins.
EXIF is a widely recognized format for storing image metadata. EXIF data is useful when connecting many devices to exchange enormous numbers of image files. Without metadata, we’d have to manually check and process these files to organize them. This can quickly become a laborious and inefficient task.
In this tutorial, we’ll learn how to sort and categorize photos based on their creation dates using EXIF data. There are numerous methods to read and utilize this metadata. We’ll look at some of the better options and utilize them to organize photographs by creation date.
2. Image Metadata and EXIF Standard
Metadata provides a brief description of data, making it easier to find, utilize, reuse, or reproduce a particular instance of data. It can refer to data or files such as music, images, databases, and computer files. For example, if we have a photo, the metadata includes the date of creation, subject category, title, method of creation, and so on.
We can categorize various image metadata into broadly three types:
- Technical metadata: Related to the technical aspects of a photo file. E.g., aperture, resolution, focal length, shutter speed, ISO, date and time, etc.
- Descriptive Metadata: Provides general details that describe the image. E.g., author, keywords, caption, title, etc.
- Administrative Metadata: Information about the legal and administrative details, if any. E.g., licensing rights, copyright information, contact information of the owner, etc.
Metadata is expressed using a variety of standardized formats, including EXIF (Exchangeable File Format), IIM (Information Interchange Model), ICC (International Color Consortium), and XMP (Extensible Metadata Platform). EXIF is the most widely adopted among all of these formats. In the following sections, we’ll mostly discuss and use metadata in EXIF format.
EXIF stands for Exchangeable File Format. It’s a standard method of storing important metadata in digital image files and includes a variety of technical information about the image. It’s one of the most well-known metadata formats, and the majority of camera manufacturers currently use it.
EXIF 1.0 was launched in October 1995, and the current version is 3.0. EXIF can be applied to both audio and image files. But in this tutorial, we’ll focus mainly on images.
3. Using ExifTool to Sort Images
ExifTool is a powerful command-line tool and library used for reading, writing, and editing metadata in various file formats. It is written in Perl and is platform-independent. Which means we can use this tool on a variety of operating systems, such as Windows, Linux, etc.
The tool supports many different metadata formats, including EXIF, GPS, XMP, JFIF, etc. Also, we can use this tool on various image formats and extract metadata from them, including JPEG, TIFF, PNG, etc. It’s one of the most well-known solutions to manage and view the metadata information of files.
3.1. Installation
To use ExifTool, we first need to download and install it on our system. Since it’s platform-agnostic, we can use ExifTool on various operating systems. Here’s how we can install ExifTool on Unix-based systems:
# For Debian and Ubuntu systems
$ sudo apt install libimage-exiftool-perl
# For CentOS and other RPM-based systems
$ sudo yum install perl-Image-ExifTool
This installs ExifTool on our systems. We can check ExifTool’s version number to verify its successful installation:
$ exiftool -ver
12.76
At the time of this writing, the most current version of ExifTool was 12.76.
3.2. Usage in Sorting Images
We can use ExifTool to list various metadata for any image. Now, for our particular use case of sorting the images according to the creation date, we need to access the particular metadata related to image creation.
For example, we can access this specific metadata for an image:
$ exiftool -r '-filename<createdate' -d '%Y-%m-%d_%H_%M_%S%-c.%le' <directory>
Let’s try to understand the arguments in the above command:
- The -r option denotes to recursively apply the following rule to all the files in the directory and subdirectories.
- The -filename< createdate part renames the filename using the createdate tag from EXIF metadata. Here, we could use any other tags as well, such as -modifydate.
- The -d or -dateformat defines the format for the date. The next part %Y-%m-%d_%H_%M_%S%-c.%le is the format by which the createdate tag will be formatted. Let’s break it down even further:
- %Y, %m, %d, %H, %M, %S means the year, month, day, hour, minute, second respectively.
- %-c appends a counter at the end of the filename if there is any collision.
- %le signifies the lower case file extension, which basically tells it to make the extension lower case after renaming.
- Finally, we can provide a directory name, and the operation will be performed on all the images inside that directory recursively.
3.3. An Example
Let’s see an example of this. We have a folder named photos, where we have some unsorted images initially. Let’s see how we can sort the images in the photos directory using the above command:
$ ls photos/
bike.jpg bus.jpg camelion.jpg girl.jpg lizard.jpg rose.jpg
$ exiftool -r '-filename<createdate' -d '%Y-%m-%d_%H_%M_%S%-c.%le' photos
1 directories scanned
6 image files updated
$ ls photos/
2004-08-27_13_52_55.jpg 2005-08-13_09_47_23.jpg 2008-05-04_16_47_24.jpg
2005-03-10_15_10_48.jpg 2008-03-07_09_55_46.jpg 2008-05-30_15_56_01.jpg
As we can see from the example, at the beginning that the images are unsorted according to the ls command’s default lexicographical sort. After we applied the discussed command, we have renamed all the files according to the creation date. Therefore, applying the ls command again on the same directory shows that the images are lexicographically sorted.
4. Using jhead to Sort Images
jhead is a lightweight substitute of the ExifTool. It’s an EXIF JPEG Header Manipulation Tool. It’s a command-line utility that can manipulate, change, and show the EXIF metadata of image files. Although jhead isn’t as flexible and powerful as ExifTool, its commands are shorter and easier to use.
4.1. Installation
We can run the following command to install jhead:
# For Debian and Ubuntu systems
$ sudo apt install jhead
# For CentOS and other RPM-based systems
$ sudo yum install jhead
To verify the installation, we can run:
$ jhead -V
Jhead version: 3.08
At the time of this writing, the current version of jhead is 3.08.
4.2. Sorting: by Renaming
We can also rename the images from the EXIF metadata by using jhead:
$ jhead -n<format_string> fileName
Here the -n option renames the files specified according to the EXIF dateTimeOriginal field. The format_string part is optional, which formats the information from the dateTimeOriginal field accordingly. If the target name is the same for multiple files, the name will be appended with letters or digits of the alphabet. Lastly, the fileName argument can contain one or more files, or even contain file names with wildcard notations.
Let’s see an example of using jhead on the photos folder from earlier:
$ jhead -n%Y%m%d%H%M *.jpg
bike.jpg --> 200408271352.jpg
bus.jpg --> 200803070955.jpg
camelion.jpg --> 200805301556.jpg
girl.jpg --> 200503101510.jpg
lizard.jpg --> 200508130947.jpg
rose.jpg --> 200805041647.jpg
In this example, we can see that after using the command, all the files containing .jpg in the end, signified by *.jpg got renamed with their creation date. Therefore, we have now sorted these images automatically according to their creation date.
4.3. Sorting: Without Renaming
We might not always want to rename our files, because the current names may be important to us. In that case, a workaround is to set all the image’s system timestamp to the creation date EXIF metadata. This would allow us to sort the images according to their system dates in the GUI, which is also their last modification date. We can use jhead to achieve this objective.
Let’s look at the command for setting the system timestamp or the date modified with the EXIF metadata creation date:
$ jhead -ft <filename>
The -ft option here changes the image’s modification date to the creation date as stored in EXIF metadata. And the filename is the file or files on which we wish to perform this action.
Let’s look at a practical example:
$ jhead -ft *
bike.jpg
bus.jpg
camelion.jpg
girl.jpg
lizard.jpg
rose.jpg
The modification dates for these photographs in this example have now been changed using the above command. We can now navigate to the top menu and sort these photographs according to the Date Modified field. In the top menu, we have to first pick View, then Sort Images, and finally By Date. The following image demonstrates this in action:
We can see from the above image that the images in the folder are now sorted, and the date displayed corresponds to the images’ creation date. We could also sort the photographs by selecting List View from the top bar and then clicking on Date Modified to sort them in ascending and descending orders.
5. Conclusion
In this article, we learned about image metadata, specifically the most common metadata standard, EXIF. EXIF contains a variety of crucial information about an image that aids in its recognition and categorization.
We also go to know about two command line programs, ExifTool and jhead. We used them to arrange photos based on their creation dates. Finally, we saw how to do this sorting with or without renaming the photos.