gexiv2 Python support

Here is a short example of how to use gexiv2 in Python. This will work equally well with either Python 2 or 3, which makes gexiv2 an excellent replacement for pyexiv2, which only supports Python 2. Developers who wish to port their python applications from 2 to 3 will want to port from pyexiv2 to gexiv2 first, and then from 2 to 3 afterwards.

   1 #!/usr/bin/python3
   2 
   3 from gi.repository import GExiv2
   4 
   5 exif = GExiv2.Metadata('IMG_1234.JPG')
   6 
   7 # longitude, latitude, altitude
   8 exif.set_gps_info(-79.3969702721, 43.6295057244, 76)
   9 
  10 # Using dict notation like this reads/writes RAW string values
  11 # into the EXIF data, with no modification/interpolation by GExiv2.
  12 # Refer to GExiv2.py to see what kind of convenience methods are
  13 # supplied for setting/getting non-string values.
  14 IPTC = 'Iptc.Application2.'
  15 exif[IPTC + 'City'] = 'Toronto'
  16 exif[IPTC + 'ProvinceState'] = 'Ontario'
  17 exif[IPTC + 'CountryName'] = 'Canada'
  18 
  19 exif.save_file()

Also available is a slightly larger example on github, and you can also refer to GottenGeography's code, which was the first nontrivial python application ported to GExiv2.

If you're having trouble with initializing GExiv2.Metadata, see Simon Feltman's debugging tips on Launchpad.

Projects/gexiv2/PythonSupport (last edited 2014-04-11 19:30:55 by JimNelson)