Mindtunnel.com Projects

Assorted Spare Time Projects

imtag: Exif/Iptc/Xmp metadata editor

| Comments

imtag is a frontend to the pyexiv2 library that will let you ‘set’ or ‘get’ the Exif, Iptc and Xmp metadata.raw_value.

No validation of any sort is done! It is up to you to back up your images before making any changes! If you can get the command line to accept your key/value and then if the pyexiv2 library will accept it as a key/value pair, it will be set.

imtag command line help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ ./imtag --help
usage: imtag [-h] [-e] [-i] [-x] [-g key.name | -s key.name=value] [-q] [-f]
             [-p] [--seperator SEP] [--escape]
             Files [Files ...]

Dump exif, iptc and xmp data from an image file.

positional arguments:
  Files              list of image file names to operate on

optional arguments:
  -h, --help         show this help message and exit
  -e, --exif         dump exif data (default is --exif --iptc --xmp)
  -i, --iptc         dump iptc data (default is --exif --iptc --xmp)
  -x, --xmp          dump xmp data (default is --exif --iptc --xmp)
  -g key.name        keys to list, can be specified multiple times
  -s key.name=value  Key/value pairs to modify. Can be specified multiple
                     times (will warn if operating on multiple files) Use
                     key.name=NULL to delete the entry. The string passed in
                     will be interpreted as a python object, so you may pass
                     list or dict objects as well as function calls
                     (=datetime.datetime(yy,mm,dd,hh,mm)
  -q, --quiet        don't display a warning about overwriting files
  -f, --force        force setting keys on multiple files
  -p, --prefix       prefix the filename to the output (useful with -g on
                     multiple files)
  --seperator SEP    seperator string (default=":")
  --escape           escape output - can be useful if you are trying to use
                     the output strings in a script

Examples

imtag show image time
1
2
$ imtag -g Exif.Photo.DateTimeOriginal F001.JPG
Exif.Photo.DateTimeOriginal:2012:05:13 14:30:12
imtag get image keywords
1
2
$ imtag -gIptc.Application2.Keywords F001.JPG
(no output so the Iptc key does not exist in the file)
imtag set image keywords
1
2
3
4
5
6
7
8
9
10
$ imtag  -sIptc.Application2.Keywords="['Person1', 'Tag2', 'Person3']"  F001.JPG
WARNING!  I do basically NO validity checking on what you are setting.  If the
pyexiv2 library will accept your input then it will try to modify your file.
I STRONGLY recommend you back up your images before modifying the EXIF data.
You've been warned - this could destroy your file!

Use the -q option to bypass this warning
OK to continue? [y/n] y

adding md[Iptc.Application2.Keywords]=['Person1', 'Tag2', 'Person3']

Note in the above example that the value for the keyword was specified as a Python list.

And if we retrieve the keyword we see it is now set:

imtag get image keywords
1
2
$ imtag -gIptc.Application2.Keywords F001.JPG
Iptc.Application2.Keywords:['Person1', 'Tag2', 'Person3']

As a more extensive example, the following bash script will copy Exif.Photo.DateTimeOriginal, Exif.Image.DateTimeOriginal, Exif.Photo.DateTimeDigitized, Iptc.Application2.Caption and Iptc.Application2.Keywords from one image file to another and then also delete Xmp.exif.DateTimeOriginal, Xmp.dc.date Iptc.Application2.DateCreated, Iptc.Application2.TimeCreated, Exif.Image.ImageDescription Xmp.dc.description Xmp.acdsee.caption and Exif.Photo.UserComment from the destination image.

dupKeys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

IMTAG=`which imtag`

if [ "x$1" == "x" ] || [ "x$2" == "x" ]
then
  echo "usage: $0 <src> <dest>"
else
  SRC="$1"
  DST="$2"

  DTvars='Exif.Photo.DateTimeOriginal Exif.Image.DateTimeOriginal Exif.Photo.DateTimeDigitized'
  DTrem='Xmp.exif.DateTimeOriginal Xmp.dc.date Iptc.Application2.DateCreated Iptc.Application2.TimeCreated'

  CAvars='Iptc.Application2.Caption'
  CArem='Exif.Image.ImageDescription Xmp.dc.description Xmp.acdsee.caption'

  KWvars='Iptc.Application2.Keywords'
  KWrem='Exif.Photo.UserComment'

  echo -e "\nbefore:"
  for V in $DTvars $DTrem $CAvars $CArem $KWvars $KWrem
  do
      $IMTAG -p -g$V "$DST"
  done
  
  echo -e "\nnew values:"
  G="$IMTAG "
  for V in $DTvars $CAvars $KWvars
  do
      a="`$IMTAG -g$V --escape --seperator = \"$SRC\"`"
      if [ ${#a} -gt 1 ]
      then
          k="`echo \"$a\" | cut -d= -f1`"
          v="`echo \"$a\" | cut -d= -f2-`"
          G="$G -s$k=$v"
      fi
  done
  G="$G \"$DST\""

  echo -e "\ncommand: $G\n"
  eval "$G"

  echo -e "\nafter:"
  for V in $DTvars $DTrem $CAvars $CArem $KWvars $KWrem
  do
      $IMTAG -p -g$V "$DST"
  done

fi

Comments