Am trying to copy EXIF information of a Image file to the resized version of the same image using pyexiv2. Searching for a solution i stumbled upon a post in Stack Overflow. It looks like the api's used in the function is outdated and is not available in the latest version. Based on the latest document i created a function like this
def get_exif(file):
"""
Retrieves EXIF information from a image
"""
ret = {}
metadata = pyexiv2.ImageMetadata(str(file))
metadata.read()
info = metadata.exif_keys
for key in info:
data = metadata[key]
ret[key] = data.raw_value
return ret
def write_exif(originFile, destinationFile, **kwargs):
"""
This function would write an exif information of an image file to another image file
"""
exifInformation = get_exif(originFile)
metadata = pyexiv2.ImageMetadata(str(destinationFile))
for key, value in exifInformation.iteritems():
metadata[key] = value
copyrightName = kwargs.get('copyright', None)
if copyrightName != None:
metadata['Exif.Image.Copyright'] = copyrightName
try:
metadata.write()
except:
return False
else:
return True
But this ends up in an error
Python argument types in _ExifTag._setParentImage(_ExifTag, NoneType) did not match C++ signature: _setParentImage(exiv2wrapper::ExifTag {lvalue}, exiv2wrapper::Image {lvalue})
I am now clueless on what went wrong. Could someone please help me out? Thanks
EDIT
Based on @unutbu 's suggestion I made change to data.raw_value in get_exif() method to data.value but still am facing the same issue. Am pasting more information regarding this error:
Python argument types in
_ExifTag._setParentImage(_ExifTag, NoneType)
did not match C++ signature:
_setParentImage(exiv2wrapper::ExifTag {lvalue}, exiv2wrapper::Image {lvalue})
Request Method: POST
Request URL: http://localhost:8000/accounts/photography/
Django Version: 1.3.1
Exception Type: ArgumentError
Exception Value:
Python argument types in
_ExifTag._setParentImage(_ExifTag, NoneType)
did not match C++ signature:
_setParentImage(exiv2wrapper::ExifTag {lvalue}, exiv2wrapper::Image {lvalue})
Exception Location: /usr/lib64/python2.7/site-packages/pyexiv2/exif.py in _set_owner, line 107
**Traceback**
/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
response = callback(request, *callback_args, **callback_kwargs) ...
/usr/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py in _wrapped_view
return view_func(request, *args, **kwargs) ...
/home/swaroop/public_html/xyz/xyz/apps/photography/views.py in accountsPhotoList
write_exif(originFile=filePath, destinationFile=output) ...
/home/swaroop/public_html/xyz/xyz/library/imageManipulation.py in write_exif
metadata[key] = value ...
/usr/lib64/python2.7/site-packages/pyexiv2/metadata.py in __setitem__
return getattr(self, '_set_%s_tag' % family)(key, tag_or_value) ...
/usr/lib64/python2.7/site-packages/pyexiv2/metadata.py in _set_exif_tag
tag._set_owner(self) ...
/usr/lib64/python2.7/site-packages/pyexiv2/exif.py in _set_owner
self._tag._setParentImage(metadata._image) ...
Python Executable: /usr/bin/python2.7
Python Version: 2.7.2