How can the EXIF orientation tag be changed (preferably using PythonMagick)?

2.4k Views Asked by At

I'm scaling and rotating some JPEGs using PythonMagick. Ideally, I could update the EXIF Orientation tag as well. However, while I can retrieve the value of this tag, I can't seem to modify it. Consider:

from PythonMagick import Image

i = Image("image.jpg")
print i.attribute("EXIF:Orientation")
i.attribute("EXIF:Orientation", "5")
i.write("image-modified.jpg")

Running this shows the original orientation of your image:

exarkun@top:/tmp$ python broken.py 
6
exarkun@top:/tmp$

And as long as it wasn't 5 to begin with, exiftool will demonstrate that the new file has not had its orientation adjusted:

exarkun@top:/tmp$ exiftool image.jpg | grep Orient
Orientation                     : Rotate 90 CW
exarkun@top:/tmp$ exiftool image-modified.jpg | grep Orient
Orientation                     : Rotate 90 CW
exarkun@top:/tmp$ 

Why doesn't ImageMagick write out the modified orientation? How can I get it to?

1

There are 1 best solutions below

0
On

This question is similar to: Exif manipulation library for python

Also, see: Copying and Writing EXIF information from one image to another using pyexiv2

The above involves using pyexiv2 to read and write exif data. I realise this isn't using PythonMagick, but it is using a "high level" python library to write EXIF data, and at least so far as I can tell is the best (only?) solution at present.

It appears that ImageMagick is capable, so perhaps someone can expand here on how it could be done from python; see: How do I add exif data to an image?