Defining sub routine / global variables within .Exiftool_Config

Started by issam9973, February 10, 2021, 10:58:00 AM

Previous topic - Next topic

issam9973

Hi, I'm newbie to perl / exiftool !

Is it possible to define a sub routine / global variables within .Exiftool_Config then use them in the user-defined composite tags section?

Here is a toy example. Please help me correct the structure in case the above is possible. (Note: i now the toy example below can be done without subroutine but it's not the point :)!)


#---------------------------------
# File:   exiftool.config
#---------------------------------

# global variable
my $smallestDate = '1960:01:01 00:00:00';
my $largestDate =  '2960:01:01 00:00:00';

# Sub routine / function
sub mySubRoutine {
my ($res) = @_ ;
# Do some calculations
# ...
  return $res;
}

%Image::ExifTool::UserDefined = (
   'Image::ExifTool::Composite' => {

MyDateTimeMax => {
  Desire => {
  0 => 'DateTimeOriginal',
  1 => 'FileModifyDate',2 => 'FileAccessDate',3 => 'FileCreateDate',
  4 => 'FileName',
  # other date tags ...
  }, 
  ValueConv => q{
    my $r = $smallestDate;
    foreach (@val) {
    next if (not defined $_);
  $tmp = mySubRoutine $_; 
    $r = ($r lt $tmp) ? $tmp : $r;
    }; 
    return $r;
  },
  },
},
);
1; # end



- Issam

StarGeek

For a subroutine, yes.  You can even use the subroutine as an helper function on the command line, similar to DateFmt helper function.

See my user defined tag in this thread for an example.  The MyNormalize subroutine in that config file can be used on the command line to convert accented characters such as à , ê , ó into the base characters a, e, o.  Yeah, I'm a silly American who doesn't like to deal with those characters.

A global variable is a bit more difficult.  You can't access it directly if you're using ValueConv => q{ but can if you use ValueConv => sub {.  I may be wrong the first part.  I asked this once and can't remember the response.  It's in the forum someplace and I'll link if I can find it.

Using ValueConv => sub { does require a bit more work.  Take a look at the picasa_faces.config for some examples.

The config files can provide more examples and there are plenty more in the forums here.  I usually use this google search to find them.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Quote from: StarGeek on February 10, 2021, 11:17:45 AM
A global variable is a bit more difficult.  You can't access it directly if you're using ValueConv => q{ but can if you use ValueConv => sub {.  I may be wrong the first part.  I asked this once and can't remember the response.  It's in the forum someplace and I'll link if I can find it.

Here's where I previously asked about this.  It is possible.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).