From fe6639c4fb83eb9360d9983e344d0f6e7a2e3498 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 17 Aug 2015 06:35:15 -0700 Subject: Fix loading images: * images without exif data are now assumed to be in the correct orientation instead of raising an exception. * Images are now converted from their color mode to RGBA so they can be saved as JPEG. --- presentty/image.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/presentty/image.py b/presentty/image.py index d82face..2dbd9ad 100644 --- a/presentty/image.py +++ b/presentty/image.py @@ -47,7 +47,11 @@ class ANSIImage(urwid.Widget): def _loadImage(self): image = PIL.Image.open(self.uri) image.load() - exif = image._getexif() + try: + exif = image._getexif() + except AttributeError: + # No info on whether we should rotate image + exif = None if exif: orientation = exif.get(274, 1) if orientation == 1: @@ -58,8 +62,6 @@ class ANSIImage(urwid.Widget): image = image.rotate(-90) elif orientation == 8: image = image.rotate(90) - else: - raise Exception("unknown orientation %s" % orientation) return image def pack(self, size, focus=False): @@ -105,6 +107,7 @@ class ANSIImage(urwid.Widget): stdout=subprocess.PIPE, stderr=subprocess.PIPE) image = self._loadImage() + image = image.convert('RGBA') image.save(jp2a.stdin, 'JPEG') jp2a.stdin.close() data = jp2a.stdout.read() -- cgit v1.2.3