[Digikam-users] Retrieving metadata

Martin Burnicki martin.burnicki at gmx.de
Mon Oct 24 18:55:47 BST 2011


Samuel Ronayette wrote:
> Hello
>
> is there a way to look for files with a specific value of a field in the
> metadata? For example, I want to search all the photos in my 'Images'
> folder that were taken with a given lens.
> The "advance search" in digikam does not seem to allow me to do so...
> If not possible in digikam, do you know a tool (under linux) that would
> allow me to do so? I installed the "exif" program, but it doesn't see this
> "LensModel" field in the metadata
> (note that the field "LensModel" does appear in the metadata in digikam,
> when I clik on the tab "Notes du fabricant", but not in the "EXIF" tab)

The exiftool program can be used to list all metatags from one or more images. 

When I started to use this program I stumbled across the fact that the program 
distinguishes between "human readable" tag names and "real" tag names. This 
may lead to confusion if you want to list all tags first, and then change one 
of the listed tags, e.g.:

exiftool img_0235.jpg prints (among others):
..
Lens Model                      : EF-S55-250mm f/4-5.6 IS
..

Please note the tag name listed above contains spaces. As far as I know there 
is no way to specify a tag name with space(s), if you only want to display a 
specific tag, i.e. what we'll need later.

However, if you call exiftool with parameter -s then it prints the "real tag 
names", e.g.:

exiftool -s img_0235.jpg
..
LensModel                       : EF-S55-250mm f/4-5.6 IS
..

So you can use the command

exiftool -LensModel

to print the LensModel tag of every image in the current directory. However, 
as far as I know, there is no way to let exiftool print only the names of 
every image where a specific tag has a given value.

A one-line script can help to do this. e.g.: 

for f in 2011-10-24\ My\ Latest\ Photos/*.jpg ; do exiftool -LensModel "$f"|\
grep -q "EF-S55-250mm" && echo "$f"; done

The script above loops across all .jpg files a given folder, in this 
case "2011-10-24 My Latest Photos" (please note the spaces in the directory 
name have been escaped in the command, i.e. '\ ').

Then "exiftool -LensModel" is used to print the LensModel tag of an image. The 
output is piped to the grep command which checks if the lens model tag 
matches "EF-S55-250mm" (in my case), and if it matches it prints the name of 
the file. In my case the output looks like:

2011-10-24 My Latest Photos/img_0235.jpg
2011-10-24 My Latest Photos/img_0241.jpg
2011-10-24 My Latest Photos/img_0239.jpg


A limitation of the command above arises if you want to check many files which 
are if different nested directories. In this case you can use a 2 step way to 
find all files which have the tag with the given value. First create a list 
of all image files in the specified directory and all directories below:

find "2011-10-24 My Latest Photos" -iname "*.jpg" > files.txt

Then read the file with the image names line by line and check if the named 
image has the tag you are looking for:

while IFS= read -r f; do exiftool -LensModel "$f"|grep -q "EF-S55-250mm" && \ 
echo "$f"; done < files.txt 

In my case the output is:

2011-10-24 My Latest Photos/tmp/img_0241.jpg
2011-10-24 My Latest Photos/tmp/img_0240.jpg
2011-10-24 My Latest Photos/img_0235.jpg
2011-10-24 My Latest Photos/img_0239.jpg
2011-10-24 My Latest Photos/img_0236.jpg

i.e. the latter method als finds images in a different folder and lists the 
file and folder name.

If you have to search a large number of image files then these commands may 
take some time to execute since the exiftool program is launched for each 
images. But anyway, it does what you wants.

Regards,
Martin



More information about the Digikam-users mailing list