Possible to do a multiplication when copying tags?

Started by Beholder3, May 17, 2011, 03:36:54 PM

Previous topic - Next topic

Beholder3

Hi,

I have two use cases for exiftool and I wonder if there is a way to automate some part of the manual changes:
a) I use a tele converter (e.g. x2 magnification) with a lens and the converter just routes the orignal aperture and focal length data through. So I have to manually correct all these values.
Is it possible to let exiftool do a "*2" multiplication on focal lengths?

b) Some cameras dont populate the FocalLengthin35mmFormat exif field. Since I know the crop factor (e.g. 3) of that camera I have to calculate the value and manually populate the fields.
Is it possible to let exiftool do a "*3" multiplication on copying FocalLength to FocalLengthin35mmFormat?

If it's not possible to do that (i believe so) then I'd humbly suggest this as a feature for some future release of the already great software.   :)



Phil Harvey

You can do any arbitrary manipulations/combinations/calculations with user-defined Composite tags.

See the config file documentation for some examples.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Beholder3

I see. ... And don't.

Phil, thanks for providing direction, but all I can see is that there seems to be a config file which seems to contain some PERL code.

I found a line which seems to calculate a square root but even that piece I don't really understand.

And even if I was able to create a composite tag in there I had no idea what arguments to choose in exiftool. Are these composite tags like little subprograms which execute something without needing arguments/variables themthelves?

Sorry, but I am quite lost there.

Could you help me by providing the code bit for the two cases given and how to use that then?
I know no other way other than this or me learning PERL basics first...

Phil Harvey

It's really not too difficult.  This config file would do it for you:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyFocalLength => {
            Require => 'FocalLength',
            ValueConv => '$val * 2',
        },
    },
);


Then, once the config file is installed you will have a new tag called MyFocalLength, which is just FocalLength multiplied by 2.  You can then copy it back to FocalLength with an argument like "-focallength<myfocallength" to double the FocalLength values in the file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Beholder3

Thanks! Thanks a lot!  :)

I think I need this here:


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        Converter2xFocalLength => {
            Require => 'FocalLength',
            ValueConv => '$val * 2',}
        Converter2xFNumber => {
            Require => 'FNumber',
            ValueConv => '$val * 2'}
        Sony35mm => {
            Require => 'FocalLength'
            ValueConv => '$val * 4.81'}
        Samsung35mm => {
    Require => 'FocalLength'
            ValueConv => '$val * 5.58'}
        ,
    },
);


Am I correct in opening and closing the brackets after the "=>" for each new tag?
Do I need extra "," after each closing bracket for each of the four composite tags?

Phil Harvey

Quote from: Beholder3 on May 18, 2011, 01:23:38 PM
Am I correct in opening and closing the brackets after the "=>" for each new tag?

Yes.

Quote
Do I need extra "," after each closing bracket for each of the four composite tags?

Yes again.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Beholder3

Hi Phil,

I now did the following code:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        Converter2xFocalLength => {
            Require => 'FocalLength',
            ValueConv => '$val * 2',},
        Converter2xFNumber => {
            Require => 'FNumber',
            ValueConv => '$val * 2'},
        Sony35mm => {
            Require => 'FocalLength',
            ValueConv => '$val * 4.81'},
        Samsung35mm => {
    Require => 'FocalLength',
            ValueConv => '$val * 5.58'},
        SonyVid35mm => {
    Require => 'FocalLength',
            ValueConv => '$val * 7.82'},
    },
);


Then I created an argument file called "Telekonverter2x.txt" in path "D:\PATHNAME1\PATHNAME2\PATHNAME3\" with the following content:

# Telekonverter2x
-FocalLength<Converter2xFocalLength
-FNumber<Converter2xFNumber


Now I executed exiftool on the windows command line with:
exiftool -@D:\PATHNAME1\PATHNAME2\PATHNAME3\Telekonverter2x.txt "Test 1.JPG"

Now I do get an error such as this:
Reference to nonexistent group in regex; marked by <-- HERE in m/^\PATHNAME1\P <-- HERE ATHNAME2\PATHNAME3\Telekonverter2x.txt( |$) at Image/ExifTool.pm line 2760.

I am somewhat lost now.  ???  ???
"PATHNAME1" actually is of the type "1_Pictures", meaning it start with a number, followed by an underscore and ends in letters. Same with PATHNAME2. The "HERE" points to the place directly after the Number.

Phil Harvey

Interesting.  That message occurs because I don't check the tag names for validity, and -@D:\PATHNAME1\PATHNAME2\PATHNAME3\Telekonverter2x.txt is interpreted as a tag name.

You need a space after -@.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).