Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Change Image File Timestamp to Match EXIF Data

by merlyn (Sage)
on Aug 10, 2009 at 23:40 UTC ( #787440=note: print w/ replies, xml ) Need Help??


in reply to Change Image File Timestamp to Match EXIF Data

Neat. Mine looked like this:

#!/usr/bin/env perl use strict; $|++; use Image::ExifTool qw(ImageInfo); use Time::Local; for my $file (@ARGV) { my $ii = ImageInfo($file, qw(DateTimeOriginal DateTime)) or warn("Skipping $file\n"), next; my ($created) = grep /\S/, @$ii{qw(DateTimeOriginal DateTime)}; next unless $created; warn "using $created for $file\n"; if ($created =~ s/([-+ ])(\d\d):(\d\d)$//) { my ($sign, $hour, $minute) = ($1, $2, $3); # warn "ignoring offset of $sign $hour:$minute\n"; } my @digits = $created =~ /(\d+)/g or next; if ($digits[0] < 1900) { warn "bad year $digits[0] for $file"; next; } $digits[0] -= 1900; $digits[1] -= 1; my $gmtime = timegm(reverse @digits); if ($gmtime > time or $gmtime < time - 86400*90) { warn "preposterous gmtime for $file: ", scalar gmtime $gmtime; # next; } utime($gmtime, $gmtime, $file) or warn "Cannot utime on $file: $!"; }

-- Randal L. Schwartz, Perl hacker

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.


Comment on Re: Change Image File Timestamp to Match EXIF Data
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-08-20 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (122 votes), past polls