Author Topic: Tags from RegionName  (Read 75 times)

irinaonline

  • Full Member
  • ***
  • Posts: 43
Tags from RegionName
« on: October 12, 2019, 02:00:04 AM »
1. How is it possible to scan a picture for regionnames and add the first word from the regionname as an iptc keyword (the first word is separated by a space)? And to furthermore examine this first word and if it ends with a number to split it and add the non-numeric part as a second iptc keyword. Explanation: this would simplify the creation of a parent and a child tag.

2. If no regionnames are found I would like to add the tag FACES0 and if regionnames are found I would like to add the tag FACES+<Amount of found faces>.

In how few exiftool commands could this be packed?

Thanks in advance!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15115
    • ExifTool Home Page
Re: Tags from RegionName
« Reply #1 on: October 12, 2019, 06:54:49 AM »
This may be done in a single command:

exiftool -imagedescription=FACES0 "-keywords<${regionname@;s/(\d+)/, $1/}" -sep ", " "-imagedescription<FACES+${regionname;$_=(()=/, /g)+1}" FILE

Here I have assumed that you want to write ImageDescription with your FACES# tag, but you can change this to whatever tag you want.  Also, this will overwrite existing keywords if there are any regionnames.  Change "<" to "+<" when writing keywords to add to existing keywords.

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

irinaonline

  • Full Member
  • ***
  • Posts: 43
Re: Tags from RegionName
« Reply #2 on: October 12, 2019, 11:24:45 AM »
Thank you for your help.

The face counting works great, however not for FACE0.

And could you also please look into the first point? A regionname is for example "CLIENT10 Joe Doe". I would like to create 2 keywords from the first word of the regionname: CLIENT and CLIENT10. But only if the first word ends with a number.


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15115
    • ExifTool Home Page
Re: Tags from RegionName
« Reply #3 on: October 12, 2019, 05:30:25 PM »
OK.  So when you say "add a tag" you mean "add a keyword" (for "FACES0")?  I'm guessing here.  This will be a bit tricky.  Also, I missed that you only wanted the first word.

I'll work up a new command for you when I get a chance.

So if I understand, you want ""CLIENT10 Joe Doe" to result in keywords "FACES+1", "CLIENT", "CLIENT10" if it is the only regionname in the file?

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

irinaonline

  • Full Member
  • ***
  • Posts: 43
Re: Tags from RegionName
« Reply #4 on: October 12, 2019, 05:52:27 PM »
If there is no one tagged in the photo ==> regionname is empty ==> 1 keyword to be added: FACES0

If faces are tagged ==> 1 keyword to be added: FACES<Count>

Regionname = "CLIENT10 John Doe (Las Vegas)" ==> 3 keywords to be added: CLIENT, CLIENT10, CLIENT10 John Doe
Regionname = "CLIENT Jane Doe (New York)" ==> 2 keywords to be added: CLIENT, CLIENT Jane Doe
Regionname = "VENDOR18 John (Chicago)" ==>  3 keywords to be added: VENDOR, VENDOR18, VENDOR18 John

Thank you for your time!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15115
    • ExifTool Home Page
Re: Tags from RegionName
« Reply #5 on: October 12, 2019, 10:47:23 PM »
OK, we're getting closer.  But what do you mean: "if faces are tagged"?

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

irinaonline

  • Full Member
  • ***
  • Posts: 43
Re: Tags from RegionName
« Reply #6 on: October 13, 2019, 08:13:31 AM »
If a picture is tagged with a face, then the field regionname gets populated with its name.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15115
    • ExifTool Home Page
Re: Tags from RegionName
« Reply #7 on: October 13, 2019, 10:53:07 AM »
The logic is complex enough now that this is better done with a user-defined tag.

So here you go:

Code: [Select]
> exiftool -regionname a.jpg
Region Name                     : CLIENT10 John Doe (Las Vegas), CLIENT Jane Doe (New York), VENDOR18 John (Chicago)
> exiftool -config mykeywords.config "-keywords<mykeywords" a.jpg
    1 image files updated
> exiftool -keywords a.jpg
Keywords                        : FACES+3, CLIENT, CLIENT10, CLIENT10 John Doe, CLIENT, CLIENT Jane Doe, VENDOR, VENDOR18, VENDOR18 John
> exiftool a.jpg -regionname=
    1 image files updated
> exiftool -config mykeywords.config "-keywords<mykeywords" a.jpg
    1 image files updated
> exiftool -keywords a.jpg
Keywords                        : FACES0

Attached is the config file that I used.

Note that using your criteria may result in duplicate keywords as in the example above.

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