Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Change Image File Timestamp to Match EXIF Data

by merlyn (Sage)
on Aug 10, 2009 at 23:40 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found