Media Management: Rename JPG Images Based on Metadata

Media Management: Rename JPG Images Based on Metadata

I have been doing a bit of cleanup around my home file server, and have noticed that while I have a really beautiful collections of family photographs there is no logical organization around these photos.  I have many duplicates names, which would collide in the event of trying to merge multiple directories, and even worse I have many duplicate copies of pictures from various uploads from various devices.

Today we are going to focus on one aspect of that problem, we are going to rename our JPG images based on when the photo was taken.  This will require that the camera which took the photo was writing this metadata to the image in the EXIF format, or that you have manually coded the correct dates in them.  Additionally it also requires that your camera have the correct time on it at the time the picture was taken.  This isn’t so much an issue in the smart phone era but it was an issue with some of my older photos.

I am doing these actions on my Fedora 18 box.  Given the correct tooling you should be able to accomplish them on any Linux.  I used two different tools jhead and exiftool.  I started with jhead as it seemed simpler, however it didn’t work on any of the photos taken with one of my old Android phones.  So I then switched to exiftool.  Both tools worked fine with iPhone photos.

Install Jhead and Exiftool

# yum install jhead perl-Image-ExifTool

Execute JHead to Rename Images

We are going to use a naming convention of YYYY-MM-DD_HH.MM.SS.jpg.  I included a snippet of the output as well.

$ jhead -autorot -nf%Y-%m-%d_%H.%M.%S *.jpg
IMG_0023.JPG --> 2012-08-27_18.14.10.jpg
File 'IMG_0024.JPG' contains no exif date stamp. Using file date
IMG_0024.JPG --> 2013-05-27_20.28.44.jpg
IMG_1351.JPG --> 2011-03-19_11.12.16.jpg
Modified: IMG_1352.JPG
IMG_1352.JPG --> 2011-03-25_19.39.30.jpg

Some of my Android images threw this error.  For those I switched to the exiftool.

Corrupt JPEG data: 233 extraneous bytes before marker 0xd9

Execute Exiftool to rename Images

Here is the exiftool equivalent of our jhead command above.

$ exiftool -r '-FileName<CreateDate' -d %Y-%m-%d_%H.%M.%S.%%e *.jpg
 630 image files updated
 63 image files unchanged