2

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?

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • I write my own imaging code, so I'm not familiar with imagemagick or pythonmagick, but what you're asking to do is pretty simple. Since you're not adding or removing an EXIF tag, you're only change it's value in-place, then why not read the file as binary, modify the single byte which needs to change and write it back? The tag in question (0x112) is pretty easy to find with very little code. – BitBank Jan 11 '12 at 19:19
  • 1
    I certainly could, but I hope I don't really need to explain why I would **prefer** to find a library with a high-level API to deal with this instead. – Jean-Paul Calderone Jan 12 '12 at 03:03
  • I understand your motivation, I just have an aversion to using additional libraries/layers if I can write the code myself because you always encounter the limitation or bug that interferes with your project. – BitBank Jan 12 '12 at 15:29
  • @Jean-PaulCalderone in `C` this is done as easy as: `MagickSetImageOrientation(wand, TopLeftOrientation);` (maybe there is something equivalent in these bindings). Now, I would suggest using something else for this task since you are going to reencode the jpeg if you continue on ImageMagick. I don't see any benefit in using this tool for the task, why would you want to lose quality (minor, yes) for the simple operation of modifying an EXIF tag ? – mmgp Jan 26 '13 at 02:55

1 Answers1

1

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?

Community
  • 1
  • 1
Sam Jacobson
  • 431
  • 5
  • 7