How do I programatically change just the year in the EXIF of my photographs?

Started by Archive, May 12, 2010, 08:54:42 AM

Previous topic - Next topic

Archive

[Originally posted by mbroowil on 2009-11-25 16:12:08-08]

I have my photos in folders labeled by year then by event in sub-folders. For example, the root directory has 1995, 1996, 1997... with folders of events within those folders. Some of the photo's "date taken" (in the picture's metadata) are correct, but some are wrong. I was hoping to use a tool ExifTool to recursively go through each folder and only make sure that the year of the photo "date taken" matches the root folder year name. I see date shifting as an option in ExifTool which won't work because some dates are certainly correct. I also see date modify options but am not sure if it will work with just the year because it would overwrite correct dates in addition to changing the year.

Really I'm just worried about overwriting correct data.  If I could just change the year of all the photos, and only the year, I would at least know that if it had a correct date, it would remain.  Then I would be able to sort photos by year in applications like Picasa.

I'm new at this too, so I'm sorry if my question is basic but I couldn't find a thread that covered it.

Thanks in advance!

Archive

[Originally posted by exiftool on 2009-11-25 16:32:17-08]

To just find out which images have the wrong date,
you use this command assuming that the images are all
in subdirectories named by year in the current directory:

Code:
exiftool -r -if "$datetimeoriginal !~ /^$directory" -datetimeoriginal *

(use single instead of double if you are on Mac or Linux)

To fix all dates automatically is somewhat trickier, but
could be done very effectively with this config file:

Code:
%Image::ExifTool::UserDefined = (
    # Composite tags are added to the Composite table:
    'Image::ExifTool::Composite' => {
        FixDateTimeOriginal => {
            Require => {
                0 => 'DateTimeOriginal',
                1 => 'Directory',
            },
            ValueConv => q{
                $val[1] =~ /((20|19)\d{2})/ or warn("No DateTimeOriginal"), return undef;
                my $year = $1;
                $val[0] =~ /$year/ and warn("Year is OK"), return undef;
                $val[0] =~ s/((20|19)\d{2})/$year/ or
                           warn("Bad date format"), return undef;
                return $val[0];
            },
        },
    },
);
1; #end

And this command:

Code:
exiftool "-datetimeoriginal<fixdatetimeoriginal" -r DIR

However, this would only fix DateTimeOriginal, and you likely want
to also fix CreateDate and ModifyDate.  You can do all 3 at the same
time with the necessary definitions and command-line arguments.

- Phil