正在尝试使用pyexiv2将图像文件的EXIF信息复制到同一图像的调整大小版本。为了寻找解决方案,我在Stack Overflow上偶然发现了一篇文章。看起来,函数中使用的api已经过时,而且在最新版本中不可用。根据最新的文档,我创建了这样一个函数
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但是这最终导致了一个错误
Python参数类型在_ExifTag._setParentImage(_ExifTag,NoneType)中与C++签名不匹配:_setParentImage(exv2包装::ExifTag {lvalue},exv2包装::C++ {lvalue})
我现在对出了什么错一无所知。有人能帮帮我吗?谢谢
编辑
根据@unutbu的建议,我将get_exif()方法中的get_exif()方法更改为data.value,但仍然面临相同的问题。正在粘贴有关此错误的更多信息:
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发布于 2013-08-19 16:05:09
使用pyexiv2版本0.3,@user2431382的解决方案将不允许将EXIF标记写入destination_file != source_file。以下版本适用于我:
m1 = pyexiv2.ImageMetadata( source_filename )
m1.read()
# modify tags ...
# m1['Exif.Image.Key'] = pyexiv2.ExifTag('Exif.Image.Key', 'value')
m1.modified = True # not sure what this is good for
m2 = pyexiv2.metadata.ImageMetadata( destination_filename )
m2.read() # yes, we need to read the old stuff before we can overwrite it
m1.copy( m2 )
m2.write()发布于 2013-05-29 07:05:18
而不是metadata['Exif.Image.Copyright'] = copyrightName
您必须使用语法作为
metadata['Exif.Image.Copyright'] = pyexiv2.ExifTag('Exif.Image.Copyright', copyrightName)注意: copyrightName值应为"Exif.Image.Copyright“字符串
全例
import pyexiv2
metadata = pyexiv2.ImageMetadata(image_name)
metadata.read()
metadata.modified = True
metadata.writable = os.access(image_name ,os.W_OK)
metadata['Exif.Image.Copyright'] = pyexiv2.ExifTag('Exif.Image.Copyright', 'copyright@youtext')
metadata.write()希望这能帮到你
https://stackoverflow.com/questions/8770121
复制相似问题