Posted on 2005-10-26 23:15:10-07 by exiftool in response to 1240
Re: SetNewValuesFromFile using XMP Template
Hi Thorsten,

In general, writing just a new header is not possible because if the length of any information changes the rest of the data must shift to accommodate the new size. There are special cases of course, but I like to keep ExifTool general if possible.

As far as the open filehandle goes, it is easy to write a perl wrapper which edits a file in place if you want (by first writing the file to memory). Here is an example of a 5-line subroutine to do this, along with script to test it out:

#!/usr/bin/perl -w use strict; require Image::ExifTool; my $file = shift or die "please specify file name\n"; sub WriteFileHandleInPlace($$) { my ($exifTool, $fh) = @_; my $buff; $exifTool->WriteInfo($fh, \$buff) >= 0 or return 0; return(seek($fh, 0, 0) and print $fh $buff); } open FILE, "+<$file" or die "Can't open file"; my $exifTool = new Image::ExifTool; $exifTool->SetNewValue(Comment => 'test'); WriteFileHandleInPlace($exifTool, \*FILE) or warn "Error\n"; close FILE;
Direct Responses: 1244 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.