範例:
https://github.com/agschwender/pilbox/blob/af3b5050acf492ed584ae5a3c2813e1fe207a762/pilbox/image.py
_orientation_to_rotation = { 3: 180, 6: 90, 8: 270 } deg = 0 if self._orig_format == "JPEG": try: exif = self.img._getexif() or dict() deg = _orientation_to_rotation.get(exif.get(274, 0), 0) except Exception: logger.warn('unable to parse exif') self.img = self.img.rotate(360 - int(deg))
相關文章:
Does PNG contain EXIF data like JPG?
http://stackoverflow.com/questions/9542359/does-png-contain-exif-data-like-jpg
安裝Pillow
在命令行下直接通過pip安裝:
pip install pillow
或
python -m pip install pillow
如果遇到Permission denied安裝失敗,請加上sudo重試。如果同時有 python2 + python3 請把上面的 python 換成 python3 即可。