Line breaks and "code replacement"

Started by desgphoto, May 09, 2010, 11:01:25 AM

Previous topic - Next topic

desgphoto

Hi,

how can I remove line breaks, special chars and/or single words from a XMP:description field? I'm pretty new with exiftool and have studied the docs and the forum to find a solution for this problem. Currently, I found this piece of code:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewCaption => {
            Require => 'Caption-Abstract',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
        NewDescription => {
            Require => 'XMP:Description',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
    },
);


But I can do whatever I want - it will not work for me. In principle I need to replace some words within the XMP-dc:description and the XMP-dc:author field, but I really don't no how....


Please can you help me.
Thanks a lot.

Phil Harvey

You're looking in the right place.  The example you found converts linefeeds to spaces in XMP:Description.  You can also replace words like this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewDescription => {
            Require => 'XMP:Description',
            ValueConv => q{
                $val =~ s/[\n\r]+/ /g;
                $val =~ s/\bthis\b/that/g;
                return $val;
            },
        },
    },
);
1; # end


This will translate newlines to spaces and replace all "this" to "that".  The "\b" are used to indicate word boundaries so that "this" isn't replaced inside another word.

The command line you use is:

exiftool "-xmp:description<newdescription" FILE

See the config file documentation for details about how to install the configuration file above.

You can do exactly the same thing for XMP-dc:Author.

- 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 ($).

desgphoto

Hi Phil,

sorry for my late response but thanks a lot for the help. It really works great now! My fault was that I didn't knew really how to access the template from the config file.

"-xmp:description<newdescription"


Cheers,
Lars