Skip to content

Instantly share code, notes, and snippets.

@saimn
Created February 13, 2014 23:11
Show Gist options
  • Save saimn/8985911 to your computer and use it in GitHub Desktop.
Save saimn/8985911 to your computer and use it in GitHub Desktop.
import io
from PIL import Image
from PIL import TiffImagePlugin
im = Image.open('tmp/test/in/1900-1910/00/joey.jpg')
exif = im._getexif()
data = im.info["exif"]
file = io.BytesIO(data[6:])
head = file.read(8)
info = TiffImagePlugin.ImageFileDirectory(head)
info.load(file)
print info.items()
# modify orientation
info[0x0112] = (8,)
out = io.BytesIO()
info.save(out)
out.seek(0)
dat = out.read()
im.info["exif"] = data[:14] + dat + data[exif[0x8769]:]
im.save('tmp.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment