I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-07-23 20:07:53-07 by pixelpicker
Write txt file information into jpg in batch possible?
Hello Phil :)

I'm looking for a possibility to write iptc or xmp information (Headline, Caption-Abstract, Keywords, ObjectName) in a simple .txt file back into jpg and tif files.
Up to now I use the command:
-FileName -s -s -Headline -Caption-Abstract -Keywords -ObjectName "DIR" > "DIR\keywords.txt"

to create one txt file with the above images information in a given foler DIR.

Is it possible, to to the command vice versa? Means to change the information in such a txt file and write it back into the images in that folder?

I have a lot of images in one language that have to be translated. It's necessary to be able to import the metadata in another program to to the job fast. The problem then is to reimport this new metadata into the images in batch and I hope exioftool can help me with this.

Many greetings
Bette
Direct Responses: 11199 | Write a response
Posted on 2009-07-24 11:57:45-07 by exiftool in response to 11196
Re: Write txt file information into jpg in batch possible?
Hi Bette,

The exiftool application can't do this from a single txt file. It can do this sort of thing from multiple XML files (-X option) if this will suit your needs, but you need one XML file for each image file.

But to do exactly what you want is quite simple with a bit of Perl script and the Image::ExifTool library:

#!/usr/bin/perl -w # # File: write_from_txt # # Description: Read text file and write tags to image file # # Syntax: write_from_txt TXTFILE [TAGS] # # Notes: 1) TAGS must not have leading dashes # # 2) TXTFILE must be written with a command like: # # exiftool -s DIR > out.txt # use strict; use Image::ExifTool; my $infile = shift or die "SYNTAX: write_from_txt INFILE [TAGS]\n"; open INFILE, $infile or die "Error opening '$infile'\n"; my $exifTool = new Image::ExifTool; # split lists into individual items when writing $exifTool->Options(ListSplit => ', '); # uncomment this line for additional debugging output #$exifTool->Options(Verbose => 2); my ($imageFile, $tag, $val); # loop through each line in the TXT file for (;;) { my $line = <INFILE>; if (defined $line) { if ($line =~ /^======== (.*)\n$/) { # get full file path name ($tag, $val) = ('PathName', $1); } else { # read tag name and value from TXT file next unless $line =~ /^(\S+)\s*:\s+(.*)\n$/; ($tag, $val) = ($1, $2); } } else { $tag = 'PathName'; undef $val; } if ($tag eq 'PathName') { if ($imageFile) { # write the previous file my $result = $exifTool->WriteInfo($imageFile); my $error = $exifTool->GetValue('Error'); if ($error) { warn "$error - $imageFile\n"; } elsif ($result == 2) { warn "Nothing changed - $imageFile\n"; } else { print "Updated $imageFile OK\n"; } } last unless defined $val; $imageFile = $val; $exifTool->SetNewValue(); # clear previous values print $line; next; } # set tag if specified (or if no tags specified) next if @ARGV and not grep /^$tag$/i, @ARGV; print " Writing $tag\n"; $exifTool->SetNewValue($tag, $val); } # end

Note that exiftool will attempt to write the value of any tag stored in the text file (unless you specify individual tags on the command line for this script). This includes the FileName tag, but writing of this tag will fail because it is protected.

- Phil
Direct Responses: 11203 | Write a response
Posted on 2009-07-24 21:10:41-07 by pixelpicker in response to 11199
Re: Write txt file information into jpg in batch possible?
Hello Phil :)

Thank you a lot - this looks superb. If I only could use it :).
After trying the script without success: Could you give me a hint, please?
I'm using the Windows standalone Version of Exiftool.
What I did up to now:
1) use a txt file build like created with:
exiftool -s DIR > out.txt
2) name it: translated.txt 2) put .txt in the same folder of the images to change
3) put your code in my config file and tried to call it with
exiftool -write_from_txt "J:\translation.txt" -Headline -Caption-Abstract -Keywords
- no success
4) made a .cmd and a .bat file outof your script to run it - no success
5) looked up your description in the net: The Image::ExifTool Perl Library Module - How do I use this commands? Do I put your script in the prompt? Where do I put the Syntax to define the tags?

Sorry for my nescience.

Many greetins
Bette
Direct Responses: 11204 | Write a response
Posted on 2009-07-24 21:27:23-07 by exiftool in response to 11203
Re: Write txt file information into jpg in batch possible?
Hi Bette,

I was hoping you weren't using the stand-alone version. To run this script you will need Perl installed.

With Perl and the Perl version of ExifTool installed, you should be able to name this script with a .pl extension, then just type the script name to run it.

I think this may be a bit of a challenge for you since it seems you've never done this sort of thing before. The likely spot you'll run into problems is getting the script to find the exiftool libraries. If you can't install them in the standard location, then you can always put a line like this before "use Image::ExifTool;" in the script:

BEGIN { push @INC, "c:/my_exiftool_dir/lib" }

I feel sort of like Mission Impossible: "This mission, should you decide to accept it...", except that the forum won't self-destruct in 10 seconds.

- Phil
Direct Responses: 11205 | Write a response
Posted on 2009-07-24 22:32:28-07 by pixelpicker in response to 11204
Re: Write txt file information into jpg in batch possible?
Mission impossible will start tomorrow :))

Thank you for your advice, Phil. The first Exiftool version I ever used was the complete Perl Version, but its some time ago - so I hope I'll be able to install everything without your forum or my compi self-destructing :)

Many thanks for your helpful script. When I put everything in the right place, I will give feedback.

Many greetings
Bette
Direct Responses: 11206 | Write a response
Posted on 2009-07-25 10:25:13-07 by exiftool in response to 11205
Re: Write txt file information into jpg in batch possible?
Hi Bette,

Great. You're one step ahead then.

Note that I'm on a 2-week vacation starting Monday, and will be out of contact for most of that time.

- Phil
Direct Responses: Write a response