Rename and Rotate Digital Photos With jhead

July 4, 2011 by
Filed under: command line, HowTo, image editing, linux, Ubuntu, windows 

I've recently been looking for a way to organize my digital photos by the date and time they were taken. Since I have more than one camera, it's not as simple as just sorting through file names since the cameras name the files differently. I was going to write a script using Image Magick to read the EXIF data and then the script would rename and organize the photo into a folder based on the date the photo was taken. Well, it turns out that someone has already written a handy program to take care of most of this task. The program is called jhead

Getting jhead

jhead is available for Linux, BSD, Windows, and OS-X. If you're using Ubuntu Linux, it's available in the Universe repositories and can be installed with:

sudo apt-get install jhead

Using jhead to rename files

My wife had previously gone through a bunch of images to document the first 12 months of my daughter's life. This would have been a much easier task if the images had been named and sorted by date. I used jhead to rename a few of these files with the following command:

jhead -n%Y-%m-%d_%H:%M *.JPG

The command renamed all of the files in my directory and gave this output:

Affiliate Link
1 IMG_0822.JPG --> 2010-07-18_17:11.jpg
1 IMG_0823.JPG --> 2010-07-25_13:40.jpg
2 IMG_0956.JPG --> 2010-08-14_21:07.jpg
3 IMG_1077.JPG --> 2010-09-11_11:49.jpg
3 IMG_1084.JPG --> 2010-09-19_13:31.jpg
3 IMG_1095.JPG --> 2010-09-25_11:45.jpg
4 IMG_1130.JPG --> 2010-10-19_11:45.jpg
4 IMG_1133.JPG --> 2010-10-19_11:50.jpg
4 IMG_1169.JPG --> 2010-10-25_20:43.jpg

Using the -n switch tells jhead to rename the files. Following the switch in the command is the format string to tell jhead how to do the renaming. In my case it was:

  • %Y - four digit year
  • %m - two digit month
  • %d - two digit day
  • %H - hour (24 hour format)
  • %M - minute

You could also shortcut this format using this string: %F_%R

jhead's renaming function has logic in it to avoid renaming files that have already been manually renamed. It's not foolproof, so don't depend on this feature to not overwrite your manually renamed files, but if you need to force file renaming, use the -nf switch in place of the -n switch.

Rotating images with jhead

Another useful feature of jhead is its ability to rotate you images based on the information in the EXIF header. I recently had a situation where I was uploading an image to a website and it kept showing up sideways because the camera had been on end when the picture was taken. Most photo viewing software will automatically display photos like this correctly as the image rotation is set in the EXIF header. Unfortunately in my case, the web application I was using wasn't that sophisticated. I used jhead's auto rotation function to resolve the issue.

jhead -autorot image.jpg

More information

jhead has much more functionality than I've listed here. You can view a summary of the command options by entering

jhead -h

On Linux you ca view the documentation with

man jhead

You can also view the documentation on-line at: http://www.sentex.net/~mwandel/jhead/usage.html

jhead allows you to manipulate just about anything in the EXIF header of a JPEG, so it really is a powerful tool.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>