Editing PersonInImage tag data

Started by ScannerBoy, August 15, 2021, 04:38:53 PM

Previous topic - Next topic

ScannerBoy

In the past I have used XnViewMP to allow me to add any number of names to the PersonInImage field.
The Exiftool pages describe it a as a string+ tag.
ExiftoolGUI shows the names in this field as a single string separated by '*' and plain ET displays the names as a comma separated string.

After a fair bit of searching through the ET forum, I don't really understand what sort of command line(s) I would need to update or edit the data in this tag - especially using the -stay_open convention.

Assuming I now have the following names - ET CSV convention:
Tom, Sally, Richard, Frank, Penny
and want to edit the list to Move Penny to the front, delete Frank and add Joe just after Sally.
To get
Penny, Tom, Sally, Joe, Richard

Aside from keeping track of any numbering of entries, is there a specific sequence I would need to follow?

At this point, I have been able to clear all data from the tag, but whatever data I have added, always gets added as a single string and seems to replace whatever there was before.
FWIW, I am using a temporary empty MIE file for these trials.

StarGeek

List type tags are covered under FAQ #17

Quote from: ScannerBoy on August 15, 2021, 04:38:53 PM
After a fair bit of searching through the ET forum, I don't really understand what sort of command line(s) I would need to update or edit the data in this tag - especially using the -stay_open convention.

To set the tags, you would set them separately.  This would remove any previous entries.
C:\>exiftool -P -overwrite_original -PersonInImage=Tom -PersonInImage=Sally -PersonInImage=Richard y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -PersonInImage y:\!temp\Test4.jpg
[XMP-iptcExt]   PersonInImage                   : Tom, Sally, Richard


To add a new entry to the list without affecting the others, you would use +=
C:\>exiftool -P -overwrite_original -PersonInImage+=Frank -PersonInImage+=Penny y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -PersonInImage y:\!temp\Test4.jpg
[XMP-iptcExt]   PersonInImage                   : Tom, Sally, Richard, Frank, Penny


To remove an item, you use -=
C:\>exiftool -P -overwrite_original -PersonInImage-=Frank y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -PersonInImage y:\!temp\Test4.jpg
[XMP-iptcExt]   PersonInImage                   : Tom, Sally, Richard, Penny


Note that exiftool doesn't do any bookkeeping for you.  If you add "Tom" twice, then there will be two entries for "Tom".  Also, entries are case sensitive.  "tom" and "TOM" are not the same and using -PersonInImage-=TOM will not remove "tom".  See the NoDups helper function to clean up duplicates.  NoDups has to be used as a separate command.

Quoteand want to edit the list to Move Penny to the front, delete Frank and add Joe just after Sally.
To get
Penny, Tom, Sally, Joe, Richard

I would advise you not to bother.  List type tags are unordered lists and just because you put it a certain way doesn't mean that other programs are going to respect that order when edited.  If you're thinking of a listing people left to right, for example, IMO that's something that is better placed in the description.  For example,
"(L-R) Penny, Tom, Sally, Joe, and Richard at Frank's wedding"

But if you absolutely feel the need to do this, you're better off using the -sep option.  In that case you pass everything at once and use -Sep to indicate what separates the entries. This would also make it so you don't have to worry about deleting entries, you just replace everything.  Here, in the second command, I use different characters with -sep so you can see that they are individual entries instead of a single string.
C:\>exiftool -P -overwrite_original -sep ", " -PersonInImage="Penny, Tom, Sally, Joe, Richard" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -sep ## -PersonInImage y:\!temp\Test4.jpg
[XMP-iptcExt]   PersonInImage                   : Penny##Tom##Sally##Joe##Richard

* 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).

ScannerBoy

Thank you very much for the detailed answer.
It seems XnviewMP does a fair bit of pre & post-processing, because it actually displays the names as
PersonInImage[1] Joe
PersonInImage[2] Tom ...
While the entry format needs to be "Joe;Tom;....."

Now that I have detailed 'recipe', I'll have a go at trying to make it all work with my setup:-)

StarGeek

Quote from: ScannerBoy on August 15, 2021, 05:50:38 PM
While the entry format needs to be "Joe;Tom;....."

Entry for lists tags in GUI programs is usually something like this.  There's some sort of separator character and list entries that have that separator included are often quoted.  There's been multiple times someone has asked how to remove the quotes where there were none and not mention the quotes only appear in some program.
* 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).

ScannerBoy

Yes, those quotes can at times cause confusion. It is not always easy to know what is due to the 'design' of whatever app one uses to look at the data, what is a misunderstanding on the user's part or even a bug in the app.
In a large part this uncertainty has got me to where I am now trying to build my own 'inspector'. But it is an uphill battle and I very much appreciate the helping hand by you gurus who have likely/almost surely spent a lot of time learning and experimenting to get to where they are.
And this goes doubly for Phil as the author of ET.

FWIW, I have been able to sort out just how to write to these metadata 'bags' in my tests. Though I still have to beat the code into better shape and cut out some of the test 'fudges' and fiddles.

jwilleke

So how can we get, from the Google Takeout Json files the:

{
 ...
  "people": [{
    "name": "Jane Doe"
  }, {
    "name": "John Smith"
  }],
}

from into the PersonInImage tag?

StarGeek

Run exiftool on the json file with the command in FAQ #3 to figure out the actual tag name for the name entry.

Then copy it into the image file, replacing "JSONTAG" with the actual tag name you discovered from above
exiftool -TagsFromFile %d%f.json -ext jpg -sep ", " "-PersonInImage+<JSONTAG" /path/to/files/

The -ext (-extension) option is used so exiftool doesn't try to copy JSON data back into the JSON files, which it can't do and would return an error. The -sep option is used so the data is copied as separate entries and not as a single, long entry.
* 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).

jwilleke

Thanks for the help, but I have been unable to get this wot work.

exiftool -TagsFromFile %d%f.json -ext jpg -sep ", " "-PersonInImage+<JSONTAG" /path/to/files/
Since the "JSONTAG" is an array of values,

 
 "people": [{
    "name": "Jane Doe"
  }, {
    "name": "John Smith"
  }],

Is the "JSONTAG" the "people"?

StarGeek

Quote from: StarGeek on May 25, 2024, 10:52:56 AMRun exiftool on the json file with the command in FAQ #3 to figure out the actual tag name for the name entry.

Then copy it into the image file, replacing "JSONTAG" with the actual tag name you discovered from above

You first need to figure out what tag name you need to replace "JSONTAG" with. Given the snippet you've shown me, the tag your looking for should end with "PeopleName", but I have no idea what will the first part of the tag name will be
* 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).