CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool: Edit Log


May 15, 2015, 12:33 PM

Views: 38232
Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool


I don't know enough about exiftools but from briefly reading the documentation I don't think an .args file is used in the manner you tried. It appears you are trying to use the command line interface, I am following on from the advice you were provided by Mr. Harvey, write a custom Perl script that uses Image::ExifTool.

According to Mr. Harvey I would need to parse the TXT file in Perl, and call "SetNewValue()" with appropriate tag/value pairs, then call "WriteInfo()"
, an example from his website:


use Image::ExifTool;
my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue(Author => 'Phil Harvey');


However this seems like it would always set the "Author" to a fixed value, instead I would need "Phil Harvey" to be the text after "Title" for example, but only up until the next value to look out for e.g. "URL".

Once you have parsed a txt file into a hash, you can use the code you were provided to set new values then write info:

use strict;  
use warnings;
use Image::ExifTool;

my $filepath = '/path/to/file.txt';
open my $filehandle, '<', $filepath or die "cannot open '$filepath': $!";
my %hash = map s/[\s:]*$//r, grep /\S+/, <$filehandle>;
close $filehandle;

my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue(Author => $hash{Title});
$exifTool->WriteInfo('image.jpg','modified_image.jpg'); # 3rd arg should be 'XMP' if you want to create an XMP data file.

With regards to batches, we don't know enough about your file system structure i.e. how txt files map to image files, therefore cannot provide complete advice / code. In unix I would probably make use of pathname expansion and run the command perl /path/to/dir/*, then @ARGV will contain all the batch filepaths, which can be iterated over. This approach gives you more flexibility over each batch, rather than having to code this flexibility in yourself:

for my $filepath ( @ARGV ) 


(This post was edited by Zhris on May 15, 2015, 1:09 PM)

Edit Log:
Post edited by Zhris (Enthusiast) on May 15, 2015, 12:38 PM
Post edited by Zhris (Enthusiast) on May 15, 2015, 1:09 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives