Cool utility.
A small suggestion for the next version: Instead of die()ing if it can't read a file, perhaps just warn() and skip to the next file so the rest still get processed. | [reply] |
Does the -r file test guarantee that ImageInfo
will be successful? I wonder if it would be better to omit the file test, then analyze the return status of ImageInfo to determine whether to proceed with processing. Of course, ImageInfo might just die anyway, in which case an eval might be useful to capture the failure.
| [reply] [d/l] [select] |
shoness,
I catalog images by the date each was taken.
I do too. It really sucks when the camera has the wrong date time stamp. In that case, it the EXIF data you need to modify - see (Solved) Change "Date Picture Taken" with Image::ExifTool.
I would recommend checking the return of utime since it may fail. I also agree with the other comment that perhaps you want to warn and not die. You might also want to consider not updating the time stamp unless it is different.
I am kind of interested in what tool you use to organize your pictures that depends on the timestamp of the file and not the internal Exif data. I personally have written my own tools but I completely ignore the file time stamp and don't run into the problem you are having.
| [reply] |
Beware that messing with utime can have drastic consequences. A prime example would be that most backup software is not going to be backing up your changed files, since you're lying about when they were last changed, tricking it in to thinking there were no changes...
| [reply] |
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.
| [reply] [d/l] |
Nifty tool, I was going to write one myself, but a quick search found this.
I ran this on a copied subtree of photos of my young daughter - I wrote a perl script to extract all my files from flickr as I'm making my own gallery now.
This script complained a lot with warnings, but it did do exactly what I needed first go to all images that had Exif data (I processed some wayback before I knew to preserve the exif data in gimp).
I would call it quick and dirty, its exactly what perl does best.
| [reply] |
# arw: Sony raw file suffix.
for f in *.arw *.jpg
do
exiftool -S -d "%Y%m%d%H%M.%S" -CreateDate "${f}" \
| awk '{ print $2 }' \
| xargs -I % touch -m -t % "${f}"
done
| [reply] [d/l] |