diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-11-22 20:48:55 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-11-22 20:48:55 +0100 |
commit | 8a8132dca046630303041f51107ae9e9db46afa9 (patch) | |
tree | 3ef09b18f0dcb7fb525e490f69a3a853fff5d402 /src | |
parent | 3c3b2cf45853af138b645cae700bdbb8352ce158 (diff) | |
download | pyexiv2-8a8132dca046630303041f51107ae9e9db46afa9.tar.gz |
Update the cache of EXIF tags after modifying the EXIF thumbnail.
Diffstat (limited to 'src')
-rw-r--r-- | src/pyexiv2/exif.py | 30 | ||||
-rw-r--r-- | src/pyexiv2/metadata.py | 2 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/pyexiv2/exif.py b/src/pyexiv2/exif.py index c2d121e..0acb775 100644 --- a/src/pyexiv2/exif.py +++ b/src/pyexiv2/exif.py @@ -423,19 +423,19 @@ class ExifThumbnail(object): The image is either a TIFF or a JPEG image. """ - def __init__(self, _image): - self._image = _image + def __init__(self, _metadata): + self._metadata = _metadata @property def mime_type(self): """The mime type of the preview image (e.g. ``image/jpeg``).""" - return self._image._getExifThumbnailMimeType() + return self._metadata._image._getExifThumbnailMimeType() @property def extension(self): """The file extension of the preview image with a leading dot (e.g. ``.jpg``).""" - return self._image._getExifThumbnailExtension() + return self._metadata._image._getExifThumbnailExtension() def write_to_file(self, path): """ @@ -445,14 +445,24 @@ class ExifThumbnail(object): :param path: path to write the thumbnail to (without an extension) :type path: string """ - self._image._writeExifThumbnailToFile(path) + self._metadata._image._writeExifThumbnailToFile(path) + + def _update_exif_tags_cache(self): + # Update the cache of EXIF tags + keys = self._metadata._image._exifKeys() + self._metadata._keys['exif'] = keys + cached = self._metadata._tags['exif'].keys() + for key in cached: + if key not in keys: + del self._metadata._tags['exif'][key] def erase(self): """ Delete the thumbnail from the EXIF data. Removes all Exif.Thumbnail.*, i.e. Exif IFD1 tags. """ - self._image._eraseExifThumbnail() + self._metadata._image._eraseExifThumbnail() + self._update_exif_tags_cache() def set_from_file(self, path): """ @@ -465,13 +475,15 @@ class ExifThumbnail(object): :param path: path to a JPEG file to set the thumbnail to :type path: string """ - self._image._setExifThumbnailFromFile(path) + self._metadata._image._setExifThumbnailFromFile(path) + self._update_exif_tags_cache() def _get_data(self): - return self._image._getExifThumbnailData() + return self._metadata._image._getExifThumbnailData() def _set_data(self, data): - self._image._setExifThumbnailFromData(data) + self._metadata._image._setExifThumbnailFromData(data) + self._update_exif_tags_cache() data = property(fget=_get_data, fset=_set_data, doc='The raw thumbnail data. Setting it is restricted to ' + diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index 362b9ac..a121286 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -397,6 +397,6 @@ class ImageMetadata(MutableMapping): def exif_thumbnail(self): """A thumbnail image optionally embedded in the EXIF data.""" if self._exif_thumbnail is None: - self._exif_thumbnail = ExifThumbnail(self._image) + self._exif_thumbnail = ExifThumbnail(self) return self._exif_thumbnail |