summaryrefslogtreecommitdiff
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)
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):
47 def _loadImage(self): 47 def _loadImage(self):
48 image = PIL.Image.open(self.uri) 48 image = PIL.Image.open(self.uri)
49 image.load() 49 image.load()
50 exif = image._getexif() 50 try:
51 exif = image._getexif()
52 except AttributeError:
53 # No info on whether we should rotate image
54 exif = None
51 if exif: 55 if exif:
52 orientation = exif.get(274, 1) 56 orientation = exif.get(274, 1)
53 if orientation == 1: 57 if orientation == 1:
@@ -58,8 +62,6 @@ class ANSIImage(urwid.Widget):
58 image = image.rotate(-90) 62 image = image.rotate(-90)
59 elif orientation == 8: 63 elif orientation == 8:
60 image = image.rotate(90) 64 image = image.rotate(90)
61 else:
62 raise Exception("unknown orientation %s" % orientation)
63 return image 65 return image
64 66
65 def pack(self, size, focus=False): 67 def pack(self, size, focus=False):
@@ -105,6 +107,7 @@ class ANSIImage(urwid.Widget):
105 stdout=subprocess.PIPE, 107 stdout=subprocess.PIPE,
106 stderr=subprocess.PIPE) 108 stderr=subprocess.PIPE)
107 image = self._loadImage() 109 image = self._loadImage()
110 image = image.convert('RGBA')
108 image.save(jp2a.stdin, 'JPEG') 111 image.save(jp2a.stdin, 'JPEG')
109 jp2a.stdin.close() 112 jp2a.stdin.close()
110 data = jp2a.stdout.read() 113 data = jp2a.stdout.read()