python 2.7 - Write EXIF-data from TIF (read with exifread) to JPEG-file using PIL (Pillow) -


i'm writing function specialized image manipulation , saves image in jpeg format. naturally, metadata should preserved as possible. i'm using pil (pillow) , succeeded jpeg files input data, since pil able read exif-data in case.

however, tif images info-dictionary not contain 'exif'-key. using module exifread, reading exif data works fine, so

import exifread f = open('tifimage.tif') img_exif = exifread.process_file(f) f.close() 

now i'd pass exif-data pil when saving, e.g.

img.save(filename, "jpeg", exif = img_exif) 

but cannot find out how format exif data properly, since come in dict type exifread, need in raw-string format or read-only-buffer pil.

any highly appreciated!

what looking pyxif: https://pypi.python.org/pypi/pyxif

the library doing that.

you can grab current exif information from:

im = image.open(file_path) exif_data = im.info['exif'] 

then can convert in dictionary pyxif using:

zeroth_ifd, exif_ifd, gps_ifd = pyxif.load(file_path) 

or

zeroth_ifd, exif_ifd, gps_ifd = pyxif.load(exif_data) 

then can modify exif dictionary , when save image, can use:

zeroth_ifd[pyxif.zerothifd.artist] = args.artist zeroth_ifd[pyxif.zerothifd.copyright] = args.copyright  exif_ifd[pyxif.exififd.pixelxdimension] = size[0] exif_ifd[pyxif.exififd.pixelydimension] = size[1]  exif_bytes = pyxif.dump(zeroth_ifd, exif_ifd, gps_ifd)  im.save(output_path, "jpeg", quality=85, exif=exif_bytes) 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -