Inserting part of filename in xmp:description field

Started by FlyingDutchman, May 15, 2011, 05:01:08 PM

Previous topic - Next topic

FlyingDutchman

Since the beginning of time I have used the following convention for my image filenames: "<number><special indicator> <location> - <description>.jpg", e.g.
2421E Rio de Janeiro - Cristo Redentor.jpg
2917 Ouro Prêto - Museu da Inconfidência.jpg

I started to use Picasa and want to insert a caption, based on the "<location> - <description>", e.g.
Rio de Janeiro - Cristo Redentor
Ouro Prêto - Museu da Inconfidência

After some hours of puzzling, I finally figured it out. I created 2 user-defined tags in .ExifTool_config, one tag ("BaseName") to strip the file extension, and one tag ("BaseNameLast"), where the characters until (and including) the first space are also stripped. Below are the results.

.ExifTool_config

%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
BaseName => {
Require => {
0 => 'FileName',
     },
ValueConv => 'my $name=$val[0]; $name=~s/\..*?$//; $name',
   },
BaseNameLast => {
Require => {
0 => 'BaseName',
     },
ValueConv => 'my $name=$val[0]; my $pos=index($name, " ")+1; $name=substr($name, $pos)',
   },
 },
);


Filename2Caption.bat

exiftool "-xmp:description<BaseNameLast" -L -ext .jpg *
exiftool "-filemodifydate<datetimeoriginal" -ext .jpg *


Notes:
- Filename2Caption.bat must be executed from the image directory, adding -r would make it recursive.
- For Picasa 3.8 the xmp:description field is used. I tried the iptc:caption-abstract field too, but Picasa 3.8 failed to read the field correctly when special characters are used. Even when the field was formatted in UTF-8.

I hope this post helps people with the same issue/objective.

Phil Harvey

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

the_roggy

I stumbled on this accidentally, but once upon a time I wrote a script for this as well.

Is is windows-only, but I think it is a bit easier to use, as it is not necessary to create user-defined tags:
for %F in (*.jpg) do "C:\Programs\Exiftool\exiftool.exe" -overwrite_original "-xmp:description=%~nF" "%F"

A scripted version (in a bat file) can be found here:
https://sites.google.com/site/picasastartersite/other-tools/filename2caption