1. 程式人生 > >[Python] 檢查照片 exif 進行自動轉向

[Python] 檢查照片 exif 進行自動轉向

_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))

相關文章: