2

I have a bunch of photos(jpeg, bmp, png) that I have arranged in such a manner that the metadata is in html form in a separate file.

I would like create some script to read this html file and edit the photos "Tags" field if possible.

My images are arranged like this: photo-"serial number".(jped/bmp/png).

The metadata is in the same folder but the file name is only the serial number with no extension

In this html file there is this line: <meta name="keywords" content="tag1, tag2, tag3, etc" />

Note that some files dont have this extra file and some images may already have the tag s field populated.

I want this done in a batch process.

If you know a better way to do this(windows/linux)please let me know.

2
  • Image 'tags' are arbitrary key value pairs. How is both the key and the value laid out in the <meta /> tag in the html file? May 1 '14 at 1:43
  • In the html file there is the <head> section, and in there there is this line: <meta name="keywords" content="tag1, tag2, tag3, etc" />
    – Dominique
    May 1 '14 at 2:50
0

Untested, as a starting point you can adapt:

for pic in *.jpeg *.bmp *.png; do
  serial="${pic%.*}"
  if test -r "${serial#photo-}"; then
    tags=`sed -n 's/.*<meta name="keywords" content="\([^"]*\)".*/\1/p' "${serial#photo-}"`
    # do what you want with "$pic" using "$tags"
  fi
done

So you iterate over all picture files, test if you can read the file with the prefix and extension removed, and then cut the tags out of the meta data file. I'm not sure what tool you intend to use for meta data editing of the pictures.

0

Before processing all your files better set the desired field with your favorite GUI tool. Then analyze the file with exiftool:

exiftool -XMP:all -IPTC:all test.jpg

It will print the exact name of the field. After that you can batch process all files. For example, to set XMP:description, issue:

exiftool -XMP:description="the" test.jpg

The alternative are the identify and the convert tools from package ImageMagick.

To extract from html I recomment the perl package HTML-Tree

Given the file test.html with the following content:

<html><head>
<meta name="keywords" content="tag1, tag2, tag3, etc" />
</head>
<body></body>

run this perl script to extract the tags:

use HTML::TreeBuilder 5 -weak; # Ensure weak references in use
my $tree = HTML::TreeBuilder->new; # empty tree
$tree->parse_file("test.html");
my $meta = $tree->look_down(
  _tag => "meta",
  name => "keywords"
);
print $meta->attr("content");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.