Skip to content Skip to sidebar Skip to footer

Copying And Writing Exif Information From One Image To Another Using Pyexiv2

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 loo

Solution 1:

With pyexiv2 version 0.3, the solution of @user2431382 will not allow to write the EXIF tags to destination_file != source_file. The following version works for me:

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()

Solution 2:

Instead of metadata['Exif.Image.Copyright'] = copyrightName

You have to use syntax as

metadata['Exif.Image.Copyright']  = pyexiv2.ExifTag('Exif.Image.Copyright', copyrightName)

Note: copyrightName value should be string for "Exif.Image.Copyright"

Full example

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()

hope this may help you

Post a Comment for "Copying And Writing Exif Information From One Image To Another Using Pyexiv2"