PyQt4 QPixmap Rotating Jpg according to EXIF
Question: Consider [simple `PyQt4` app, loading picture with
`QPixmap`](http://zetcode.com/tutorials/pyqt4/widgets2/) and [scaling with
ratio](http://stackoverflow.com/a/9351984/544721).

Crucial part of code:

    
    
    from PyQt4 import QtGui, QtCore
    (...)
    pixmap = QtGui.QPixmap("example.jpg")
    pixmap = pixmap.scaled(1100, 1800, QtCore.Qt.KeepAspectRatio)
    

I've been surprised when I saw my photos in wrong rotation.

I suppose, the reason is that photos contain `EXIF` information about camera
position, which should be considered and rotation applied:

    
    
    $ exiftool example.jpg  | grep -i rot
    Orientation                     : Rotate 270 CW
    Auto Rotate                     : Rotate 270 CW
    Rotation                        : 270
    

How to make this with `PyQt4`, staying close to original short form of
program... preferably _short &sweet_ and _pythonic_ way?


Answer: You need a way to read and parse the EXIF information. (Py)Qt doesn't have
that functionality built-in. But there are nice Python tools out there, like
[`pyexiv2`](http://tilloy.net/dev/pyexiv2/overview.html),
[`EXIF.py`](https://github.com/ianare/exif-py),
[`PyExifTool`](http://smarnach.github.com/pyexiftool/).

Once you get the rotation angle, then it's easy to apply it to your `QPixmap`:

    
    
    pixmap = pixmap.scaled(1100, 1800, QtCore.Qt.KeepAspectRatio)
    pixmap = pixmap.transformed(QtGui.QTransform().rotate(angle))
    

