Quickie perl hack to fix up image timestamps with Exif data

Tue Oct 21 2008 22:34:36 GMT-0700 (Pacific Daylight Time)

tags: perl hack exif image timestamp

canon

Ooops! I've been organizing image files recently from my camera and realized that I was losing timestamps when moving them to a remote Samba share. Fortunately, image formats and cameras these days are smart enough to embed the original timestamp inside the image itself (assuming you have a moderately recent camera and assuming you've gone thru the process of configuring the date/time).

I hacked up the almost trivial perl script below to touch each file with the data from the exif data.


#!/usr/bin/perl # Touch files with Exim timestamps use strict; foreach my $f (@ARGV){    my $d = jhead $f | grep 'Date/Time';    chomp $d;    $d =~ s/^Date/Time.*: (d+):(d+):(d+) (d+):(d+):(d+)/$1$2$3$4$5.$6/;    touch -t "$d" "$f"; }

The script depends on the jhead tool to get the data from the image, but the rest is dead simple.