~robru/nautilus-image-manipulator/gexiv2

« back to all changes in this revision

Viewing changes to nautilus_image_manipulator/ImageManipulations.py

  • Committer: Robert Bruce Park
  • Date: 2012-12-31 23:36:46 UTC
  • Revision ID: robert.park@canonical.com-20121231233646-tuthus16tlygzad0
Port to GExiv2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import Image
23
23
import logging
24
24
try:
25
 
    import pyexiv2
 
25
    from gi.repository import GExiv2
26
26
except ImportError:
27
27
    pass
28
28
 
161
161
        if not (skip or retry or cancel):
162
162
            try:
163
163
                # Load EXIF data
164
 
                exif = pyexiv2.ImageMetadata(fileName)
165
 
                exif.read()
 
164
                exif = GExiv2.Metadata(fileName)
166
165
                # Change EXIF image size to the new size
167
 
                exif["Exif.Photo.PixelXDimension"] = int(width)
168
 
                exif["Exif.Photo.PixelYDimension"] = int(height)
 
166
                exif["Exif.Photo.PixelXDimension"] = str(int(width))
 
167
                exif["Exif.Photo.PixelYDimension"] = str(int(height))
169
168
                # Copy the EXIF data to the new image
170
 
                newExif = pyexiv2.ImageMetadata(newFileName)
171
 
                newExif.read()
172
 
                exif.copy(newExif)
173
 
                newExif.write()
174
 
            except UnicodeDecodeError as e:
175
 
                # Can happen when the filename contains non-ASCII characters
176
 
                str = "Could not update exif data due to UnicodeDecodeError: %s" % e
177
 
                str += "\nHint: The filename/path probably contains non-ASCII characters"
178
 
                str += "\n%s" % fileName
179
 
                str += "\n%s" % newFileName
180
 
                logging.error(str)
 
169
                newExif = GExiv2.Metadata(newFileName)
 
170
                for tag in exif.get_exif_tags():
 
171
                    newExif[tag] = exif[tag]
 
172
                newExif.save_file()
181
173
            except NameError:
182
 
                logging.info("pyexiv2 is not available, EXIF data won't " \
183
 
                             "be copied over")
 
174
                logging.info(
 
175
                    "GExiv2 is not available, EXIF data won't be copied over")
184
176
        return (skip, cancel, newFileName)
185
177
 
186
178
    def pack_images(self):