Hi
Trying to find way to search through all fields of all groups.
Actually first idea was to use OS' search tool with "file contents" option, but it ignores images.
So I tested
$ exiftool -ImageDescription IMG_20230612_171812_HDR.jpg
Image Description : red oak
and
$ exiftool -if '$ImageDescription =~ /(bzzzz|Oak)/i' -p '$directory/$filename' IMG_20230612_171812_HDR.jpg
./IMG_20230612_171812_HDR.jpg
That is one single field. Is it possible to do something like this:
$ exiftool -if '$all:all =~ /(bzzzz|Oak)/i' -p '$directory/$filename' .
No, I don't believe there's a way to simply do this.
The best that I can think of is to create a shortcut tag that contains the most likely fields you are going to search through. For example, I have a shortcut called "CommonStringTags" which contains 34 of the most common simple string tags I deal with. I can use that to check if any of those tags are equal to a specific value.
Example:
C:\>exiftool -G1 -a -s -ImageDescription y:\!temp\Test4.jpg
[IFD0] ImageDescription : red oak
C:\>exiftool -G1 -a -s -if "$CommonStringTags=~/OAK/i" -filename y:\!temp\Test4.jpg
[System] FileName : Test4.jpg
C:\>exiftool -P -overwrite_original -ImageDescription=test y:\!temp\Test4.jpg
1 image files updated
C:\>exiftool -G1 -a -s -if "$CommonStringTags=~/OAK/i" -filename y:\!temp\Test4.jpg
1 files failed condition
A simplified version added to the example config file (https://exiftool.org/config.html) would look like this
# Shortcut tags are used when extracting information to simplify
# commonly used commands. They can be used to represent groups
# of tags, or to provide an alias for a tag name.
%Image::ExifTool::UserDefined::Shortcuts = (
MyShortcut => ['exif:createdate','exposuretime','aperture'],
MyAlias => 'FocalLengthIn35mmFormat',
CommonStringTags => ['ImageDescription','Description','Caption-Abstract'],
);
Interesting question.
The API Filter option acts on all tags, so you could set a UserParam in the filter and test this in the -if statement:
exiftool -api filter='/(bzzzz|Oak)/i and $self->Options(UserParam=>"MyVar=1")' -if '$myvar' -p '$directory/$filename' -r DIR
This seems to work when I test it here.
- Phil
It doesn't seem to work here
C:\>exiftool -G1 -a -s -ImageDescription y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[IFD0] ImageDescription : red oak
======== y:/!temp/Test4.jpg
[IFD0] ImageDescription : something else
2 image files read
C:\>exiftool -api filter="/(bzzzz|Oak)/i and $self->Options(UserParam=>'MyVar=1')" -if "$myvar" -ImageDescription y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
Image Description : red oak
======== y:/!temp/Test4.jpg
Image Description : something else
2 image files read
Is there any other metadata in Test4.jpg that matches "bzzzz" or "oak" ?
- Phil
I always clear the data with -All= when testing. I ran it again, using a non-existent config file to remove the possibility of one of my user-defined tags having a matching entry.
C:\>exiftool -P -overwrite_original -all= -ImageDescription="red oak" y:\!temp\Test3.jpg
1 image files updated
C:\>exiftool -P -overwrite_original -all= -ImageDescription="something else" y:\!temp\Test4.jpg
1 image files updated
C:\>exiftool -G1 -a -s -ImageDescription y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[IFD0] ImageDescription : red oak
======== y:/!temp/Test4.jpg
[IFD0] ImageDescription : something else
2 image files read
C:\>exiftool -config null -G1 -a -s y:\!temp\Test3.jpg y:\!temp\Test4.jpg
Config file not found
======== y:/!temp/Test3.jpg
[ExifTool] ExifToolVersion : 12.63
[System] FileName : Test3.jpg
[System] Directory : y:/!temp
[System] FileSize : 661 kB
[System] FileModifyDate : 2023:03:02 12:00:00-08:00
[System] FileAccessDate : 2023:06:15 08:23:58-07:00
[System] FileCreateDate : 2023:03:02 12:00:00-08:00
[System] FilePermissions : -rw-rw-rw-
[File] FileType : JPEG
[File] FileTypeExtension : jpg
[File] MIMEType : image/jpeg
[File] ExifByteOrder : Big-endian (Motorola, MM)
[File] ImageWidth : 1920
[File] ImageHeight : 1080
[File] EncodingProcess : Baseline DCT, Huffman coding
[File] BitsPerSample : 8
[File] ColorComponents : 3
[File] YCbCrSubSampling : YCbCr4:2:0 (2 2)
[IFD0] ImageDescription : red oak
[IFD0] XResolution : 72
[IFD0] YResolution : 72
[IFD0] ResolutionUnit : inches
[IFD0] YCbCrPositioning : Centered
[Composite] ImageSize : 1920x1080
[Composite] Megapixels : 2.1
======== y:/!temp/Test4.jpg
[ExifTool] ExifToolVersion : 12.63
[System] FileName : Test4.jpg
[System] Directory : y:/!temp
[System] FileSize : 446 kB
[System] FileModifyDate : 2023:06:01 14:22:50-07:00
[System] FileAccessDate : 2023:06:15 08:24:13-07:00
[System] FileCreateDate : 2023:04:16 12:00:00-07:00
[System] FilePermissions : -rw-rw-rw-
[File] FileType : JPEG
[File] FileTypeExtension : jpg
[File] MIMEType : image/jpeg
[File] ExifByteOrder : Big-endian (Motorola, MM)
[File] ImageWidth : 1749
[File] ImageHeight : 1205
[File] EncodingProcess : Baseline DCT, Huffman coding
[File] BitsPerSample : 8
[File] ColorComponents : 3
[File] YCbCrSubSampling : YCbCr4:2:0 (2 2)
[IFD0] ImageDescription : something else
[IFD0] XResolution : 72
[IFD0] YResolution : 72
[IFD0] ResolutionUnit : inches
[IFD0] YCbCrPositioning : Centered
[Composite] ImageSize : 1749x1205
[Composite] Megapixels : 2.1
2 image files read
C:\>exiftool -config null -api filter="/(bzzzz|Oak)/i and $self->Options(UserParam=>'MyVar=1')" -if "$myvar" -ImageDescription y:\!temp\Test3.jpg y:\!temp\Test4.jpg
Config file not found
======== y:/!temp/Test3.jpg
Image Description : red oak
======== y:/!temp/Test4.jpg
Image Description : something else
2 image files read
Thanks StarGeek. I get the same result with your example commands.
Oh, silly me. I previously just tested it on 1 file, but with multiple files the UserParam isn't getting reset for the next file.
I thought I was smart by using a UserParam, but I should have just set an Exiftool member variable (which gets reset after each file if it contains a lower-case letter). The following command should work, but (unfortunately) it now relies on this undocumented ExifTool feature.
exiftool -config "" -api filter='/(bzzzz|Oak)/i and $$self{MyVar}=1' -if '$$self{MyVar}' -p '$directory/$filename' -r DIR
- Phil
P.S. -config "" defeats the config file and avoids the warning message.