Hello,
I am working on a project using ExifTool::Image and I need to change the PixelsPerUnit tags.
I have found that it is possible to use the command line to adjust the metadata
exiftool -v2 -PixelsPerUnitX=<value> image.png
but
my ($success, $errStr) = $exiftool->SetNewValue("PixelsPerUnitX"=>$value);
returns a success but viewing the meta data in the image shows that the pHYs tags remain unchanged.
I have also tried SetNewValue('PNG-pHYs:PixelsPerUnitX'=>$value)
I have used this command to alter the other metadata fields and it works fine, but this one is just not working.
Thanks
You need to call WriteInfo() on the file(s) you want changed after setting the new values to write.
Did you notice that you weren't specifying a file name? Or if you were, maybe you were only reading the information (which isn't necessary when writing).
- Phil
Edit: But you say that other tags worked, so maybe this isn't the problem. However, I just tried this myself and it worked fine:
#!/usr/bin/perl -w
use strict;
use Image::ExifTool;
my $exiftool = new Image::ExifTool;
my ($success, $errStr) = $exiftool->SetNewValue("PixelsPerUnitX"=>25);
$exiftool->WriteInfo('a.png');
I am working with an image from memory there is no file at the moment.
I do adjust and change other fields such as XResolution in the EXIF metadata and when I do my final write those values are adjusted
my($success, $errStr) = $et->SetNewValue('EXIF:XResolution', 300); # This works fine same for the IPTC values
The issue is once I SetNewValue just for the PNG-pHYs tags they are the only ones to remain unchanged after my final write.
In general, you expect this behaviour when attempting to write an "unsafe" tag (for which you must specify Protected => 1 in the call to SetNewValue), but these tags are not marked as unsafe.
Something else must be going on because there should be no difference writing to memory or a file. Perhaps you are using a really old version of the Image::ExifTool library? Do this to see what version you are using:
print "$Image::ExifTool::VERSION\n";
The ability to write the PNG physicalPixel tags was added in 9.69 (July 2014). (But then I would expect SetNewValue to return an error.)
- Phil
Sorry forgot to mention but I am using version 9.90
Could you make and post a small script that exhibits this behaviour using t/images/PNG.png from the full distribution as the test image? If I can reproduce the problem here I should be able to figure it out.
- Phil
Edit: Does the script I posted work for you using t/images/PNG.png as a.png?
Hah that protected flag did it, thanks
This is not a satisfactory solution. The following contradictions have not been resolved:
1. PixelsPerUnitX is not an "unsafe" tag, so the Protected option should have no effect.
2. You said that SetNewValue returns no error, but it should if the tag isn't getting set because it is "unsafe".
3. The script I posted works without using the Protected option.
Some work still needs to be done to understand what was happening.
- Phil
Edit: I even tried with ExifTool 9.90 just to be sure, and my script still works. I really suspect that you were using an old version by accident.