lundi 10 septembre 2007

Sort JPG images by EXIF date in Ruby

Everybody now has a digital camera, and, during special events everybody takes plenty of pictures, and you end up with all these JPG images from different cameras. Each set of pictures tells the same story from the beginning, so it would be great to be able to reinterleave all of them in order to tell one single story.

That what the folllowing little Ruby script does, thanks to the libexif-ruby library. If you run it in a directory with JPG images, it will create a subdirectory and copy all images, renaming them, prefixing with the EXIF date set by the camera.

First, install the libexif-ruby library. On Ubuntu you can type :

Then copy the following script in a ruby script file :

2 commentaires:

nipponspotter a dit…

Hi,
When I try to execute the ruby file I receive an error message:
./0_sort_jpg_exif_date.rb:10: private method `gsub' called for nil:NilClass (NoM ethodError)
from ./0_sort_jpg_exif_date.rb:10
Any idea what went wrong?
I use Ubuntu 6.06 LTS - the Dapper Drake - released in June 2006.
Thanks and best regards,
Boudewijn

Stephane a dit…

I'm not sure, but it looks like the "Date and Time" exif information could not be found in your picture.

Maybe you could try the 'exif' command line utility on your pictures to check the presence of the "Date and Time" entry.