#!/usr/bin/perl -w # Copyright (C) 2015 Brian Masney # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # This script is useful when scanning a large number of images. # Name your files like: yyyy-name, yyyMM-name or yyyMMdd-name. # Pass the filenames through this script and it will add an # Exif DateTime tag to all of your photos. while (<>) { chop; my $num = `exiv2 -pa $_ | grep Exif.Image.DateTime | wc -l`; next if $num != 0; my ($datestr) = /(^\d+)/; my $year; my $month; my $day; if (length($datestr) == 4) { $year = $datestr; $month = 7; $day = 1; } elsif (length($datestr) == 6) { ($year, $month) = $datestr =~ /^(\d{4})(\d{2})/; $day = 1; } elsif (length($datestr) == 8) { ($year, $month, $day) = $datestr =~ /^(\d{4})(\d{2})(\d{2})/; } else { print STDERR "Invalid date string $datestr\n"; exit 1; } printf("exiv2 -M\"set Exif.Image.DateTime Ascii %04d:%02d:%02d 00:00:00\" \"$_\"\n", $year, $month, $day); }