#! /usr/bin/perl -w use Fcntl; use Image::Info; use Time::Local; use strict; my $indir; # parse command line arguments for (my $i = 0; $i <= $#ARGV; $i++) { my $arg = $ARGV[$i]; my $nextarg = $ARGV[$i+1]; $nextarg = "" unless (defined $nextarg); if ($arg eq '-i') { $indir = $nextarg; } } die "no input directory specified (use -i )" unless (defined $indir); my @files; opendir(DIR,$indir); while (my $file = readdir(DIR)) { next unless ($file =~ /\.jpg$/i); push @files,$file; } foreach my $file (@files) { print "modifying '$file' ...\n"; my ($date,$time,$aperture,$exposure,$speed,$focal) = exifInfo("$indir/$file"); my ($year,$month,$mday) = split(/\-/,$date); my ($hour,$min,$sec) = split(/\:/,$time); my $stamp = timelocal($sec,$min,$hour,$mday,$month-1,$year); utime $stamp, $stamp, "$indir/$file"; #print "$date $time = $stamp\n"; } close (DIR); exit; ################################################################################ sub exifInfo { my $infile = shift; my $exif = Image::Info::image_info($infile) or die; if (my $error = $exif->{error}) { die "Can't parse image info: $error\n"; } my $aperture = ""; $aperture = "f/" . eval ($exif->{FNumber}) if (defined $exif->{FNumber}); my $exposure = ""; $exposure = sprintf("%.3f", eval ($exif->{ExposureTime})) if (defined $exif->{ExposureTime}); my $stamp = $exif->{DateTimeOriginal}; $stamp = "" unless (defined $stamp); my $speed = $exif->{ISOSpeedRatings}; $speed = "" unless (defined $speed); my $date = ""; my $time = ""; if ($stamp ne "") { ($date,$time) = split(/ /,$stamp); $date =~ s/\:/\-/g; } my $focal = ""; $focal = eval ($exif->{FocalLength}) . " mm" if (defined $exif->{FocalLength}); return ($date,$time,$aperture,$exposure,$speed,$focal); }