Thread

Posted on Fri Jul 20 15:45:15 2007 by oozy
update-write iptc or xmp based on csv file
Hello I have for example 5 files (a1.jpg, a2.jpg, a3.jpg, a4.jpg, a5.jpg) and I have this csv file
filename caption alt-text a1.jpg cap1 alt1 a2.jpg cap2 alt2 a3.jpg cap3 alt3 a4.jpg cap4 alt4 a5.jpg cap5 alt5
how can I use exiftool to read this file and update the images accordingly
Direct Responses: 5775 | Write a response
Posted on Fri Jul 20 16:23:38 2007 by exiftool in response to 5774
Re: update-write iptc or xmp based on csv file
Things like this can't be done with the current command-line interface. Instead things like this are done by writing custom scripts which use the ExifTool library to do most of the work.

I don't know the exact format of your file, but assuming that the columns are separated by tabs, and that the first row contains the filename and the actual tag names that you want to change, here is a script that will do what you want:

#!/usr/bin/perl -w use strict; BEGIN { # add script directory to include path my $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.'; unshift @INC, "$exeDir/lib"; } use Image::ExifTool; my $txt = shift or die "Syntax: SCRIPT TEXTFILE [DIR]\n"; open FILE, $txt or die "Error opening $txt\n"; my $dir = shift || ''; $dir .= '/' if $dir; my $exifTool = new Image::ExifTool; my @tags; while (<FILE>) { chomp; # split up values found in this line (assume tab delimiter) my @values = split /\t/, $_; next unless @values; unless (@tags) { $values[0] eq 'filename' or die "Expected 'filename' not found\n"; shift @values; @values or die "No tags found\n"; @tags = @values; print "Writing tags: @tags\n"; next; } my $file = $dir . shift(@values); unless (-e $file) { warn "$file not found\n"; next; } @values >= @tags or die "Not enough values for $file\n"; my $tag; $exifTool->SetNewValue(); # clear old values # set new values for all tags foreach $tag (@tags) { my $val = shift @values; $exifTool->SetNewValue($tag, $val); } # update the file my $result = $exifTool->WriteInfo($file); if ($result == 1) { print "$file updated\n"; } elsif ($result == 2) { print "$file not changed\n"; } else { print "$file - write error!\n"; last; } } # end

- Phil
Direct Responses: 5778 | 7778 | Write a response
Posted on Fri Jul 20 17:19:03 2007 by oozy in response to 5775
Re: update-write iptc or xmp based on csv file
Great exactly what I want; worked like perfect.
Write a response
Posted on Mon Apr 28 17:21:54 2008 by oozy in response to 5775
Re: update-write iptc or xmp based on csv file
Hello Phil It has been long time for this script. I need your help. How can I change the script to perpend the file that exiftool succeed to to change its metadata with something like "OK". For example, if the file name is A3232.jpg and exiftool succeeded in changing its metadata then the file name become OK-A3232.jpg or may be moving the file to a directory "DONE" without changing its name. Thank and appreciate your help
Direct Responses: 7787 | Write a response
Posted on Tue Apr 29 00:08:36 2008 by exiftool in response to 7778
Re: update-write iptc or xmp based on csv file
Just define a variable for the new filename before the "my $file" line:

my $newfile = "${dir}OK-$values[0]";

Then call WriteInfo($file,$newfile)

-Phil
Write a response