Manipulating text in List-type tags

Started by slip, May 15, 2010, 10:45:49 AM

Previous topic - Next topic

slip

Is it possible to read the Keywords tag, modify the text and then write to another tag in the same file (or a different file)?

Example:

Read the Keywords tag:   John, Mary
Write "John loves Mary" in the XMP:Instructions tag.

To extend this example:
Read the Keywords tag:  John Smith, Mary
Write "John loves Mary" in the XMP: Instructions tag.

If the above are possible, then what else can be done to manipulate text found in tags such as Keywords, Headline, etc. before writing to another (or even the same) tag?


Phil Harvey

With a bit of Perl knowledge you can create a user-defined Composite tag to do whatever you want.

See this topic for a similar discussion, and search for "UserDefined" and "Composite" in this forum to find more examples.

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

slip

Thanks for your quick reply, Phil!

Unfortunately I have no Perl knowledge.
Searching for "UserDefined" and "Composite" found only my message thread. Apparently there are no examples other than the one discussion you referenced and FAQ #3. After reading these, I created a ".ExifTool_configure" file and put that example code in it to see what would happen. My intention was to later substitute my own text for that user's added pipe character and use that code. Exiftool created a new file, renaming the original file, but nothing was changed in the new file.

As a relative newbie and Perl-ignorant, I think I need more basic guidance than what I found on the site.

-Steve

Phil Harvey

Quote from: slip on May 16, 2010, 03:22:37 PM
Searching for "UserDefined" and "Composite" found only my message thread. Apparently there are no examples other than the one discussion you referenced and FAQ #3.

Did you search all boards?  The examples will be all in the Archives section.  I found many when I did my search.

Quote
As a relative newbie and Perl-ignorant, I think I need more basic guidance than what I found on the site.

OK.  You can do what you specified with this command:

exiftool "-xmp:instructions<mykeywords" FILE

and this config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyKeywords => {
            Require => 'Keywords',
            ValueConv => q{
                my @list = ref $val eq 'ARRAY' ? @$val : ($val);
                s/(\w+).*/$1/ foreach @list;  # keep only first word of each keyword
                return join(' loves ', @list);
            },
        },
    }
);
1;  #end


- Phil

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

slip

Thanks very much!
That accelerates my progress a lot!
Now I'm reading about how to manipulate strings in Perl, and I hope I'll be able to do what I want after that.

I appreciate your support.

Steve