summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-08-17 06:35:15 -0700
committerJames E. Blair <corvus@gnu.org>2016-11-20 10:42:40 -0800
commitfe6639c4fb83eb9360d9983e344d0f6e7a2e3498 (patch)
tree16399000f63a6cc9f9d5c1f20df3bfc76c8ef866
parent712d2c47f6ac3f74ab5ab2bd4db3ed6876461b4e (diff)
downloadpresentty-fe6639c4fb83eb9360d9983e344d0f6e7a2e3498.tar.gz
presentty-fe6639c4fb83eb9360d9983e344d0f6e7a2e3498.tar.xz
presentty-fe6639c4fb83eb9360d9983e344d0f6e7a2e3498.zip
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.
-rw-r--r--presentty/image.py9
1 files 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()