Replacing tag print conversions. Best way?

Started by horshack, February 23, 2020, 11:40:12 PM

Previous topic - Next topic

horshack

I'd like to replace the generated LensID tag print conversions with my own custom strings, which I use for a file renaming exiftool invocation. The generation of the LensID strings is a bit complex, relying on multiple exif tags and varying by camera system. Rather than recreate that logic I'm using a composite tag subroutine that calls to generate the existing LensID print conversion and then converts that into the renamed LensID string I want. Is this the right strategy in terms of simplicity, reliability, and compatibility for this specific tag? If so, does my implementation below the right way to do this? It works - just want to make sure I'm doing this the optimal way.

      MyLensID => {
            Require => {
                0 => 'LensID',
            },
         ValueConv => sub {         
            my %lensNames = (
               'Nikkor Z 24-70mm f/2.8 S'          => 'Nikon_24-70mm_f2.8S',
               'Nikkor Z 35mm f/1.8 S'            => 'Nikon_35mm_f1.8S',
               'Sigma 14-24mm F2.8 DG DN | A'       => 'Sigma_14-24mm_f2.8_DN',
               'Sigma 24-70mm F2.8 DG DN | A'      => 'Sigma_24_70mm_f2.8_DN',            
               'Sony FE 200-600mm F5.6-6.3 G OSS'   => 'Sony_200-600mm',
               'Sony FE 24mm F1.4 GM'            => 'Sony_24mm_GM',

            );                  
            my ($val, $exifTool) = @_;
            my $lensIdStr = $exifTool->GetValue('LensID', 'PrintConv');
            if (exists($lensNames{$lensIdStr})) { # is a LensID i want to convert
               return $lensNames{$lensIdStr};
            } else { # use default generated LensID
               return $lensIdStr;
            }
         },
      },

Phil Harvey

Very good.  What you have done should work just fine, but the code can be simplified somewhat:

    MyLensID => {
        Require => {'LensID',
        ValueConv => q{
            my %lensNames = (
               'Nikkor Z 24-70mm f/2.8 S'         => 'Nikon_24-70mm_f2.8S',
               'Nikkor Z 35mm f/1.8 S'            => 'Nikon_35mm_f1.8S',
               'Sigma 14-24mm F2.8 DG DN | A'     => 'Sigma_14-24mm_f2.8_DN',
               'Sigma 24-70mm F2.8 DG DN | A'     => 'Sigma_24_70mm_f2.8_DN',
               'Sony FE 200-600mm F5.6-6.3 G OSS' => 'Sony_200-600mm',
               'Sony FE 24mm F1.4 GM'             => 'Sony_24mm_GM',
            );
            return $lensNames{$prt[0]} || $prt[0];
        },
    },


- 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 ($).

horshack

Thanks Phil. That's exactly the type of optimization I was looking for. I had an inkling using the $exifTool object was overkill. I originally tried using $prt within the sub construct but found it wasn't available - glad so see the sub isn't necessary. I don't know a lick of perl  :) Your reply had a small typo so I'm reprinting the corrected version here so others can benefit from your elegant solution.

Oh, and btw, exiftool is awesome - thanks for the tireless work in bringing it into the world.

         MyLensID => {
            Require => {
                0 => 'LensID',
            },
            ValueConv => q{
                my %lensNames = (
                   'Nikkor Z 24-70mm f/2.8 S'         => 'Nikon_24-70mm_f2.8S',
                   'Nikkor Z 35mm f/1.8 S'            => 'Nikon_35mm_f1.8S',
                   'Sigma 14-24mm F2.8 DG DN | A'     => 'Sigma_14-24mm_f2.8_DN',
                   'Sigma 24-70mm F2.8 DG DN | A'     => 'Sigma_24_70mm_f2.8_DN',
                   'Sony FE 200-600mm F5.6-6.3 G OSS' => 'Sony_200-600mm',
                   'Sony FE 24mm F1.4 GM'             => 'Sony_24mm_GM',
                );
                return $lensNames{$prt[0]} || $prt[0];
            },
        },

Phil Harvey

Oops.  Sorry.  I had tried to simplify the Require line to this:

        Require => 'LensID',

but I left in a "{".

- 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 ($).