Browse Source

Fix issue with determining image format.

refactor
Syfaro 2 weeks ago
parent
commit
23ac6c5cdc
1 changed files with 7 additions and 12 deletions
  1. 7
    12
      src/submission.py

+ 7
- 12
src/submission.py View File

@@ -82,27 +82,22 @@ class Submission(object):
82 82
         """Resize image to specified height and width with antialiasing"""
83 83
         image = Image.open(self.image_bytes)
84 84
 
85
-        print('attempting image resize')
86
-
87 85
         if image.height <= height and image.width <= width:
88 86
             self.image_bytes.seek(0)
89 87
             return self.image_filename, self.image_bytes
90 88
 
89
+        # need to get extension from name due to bytes not having a name
90
+        # when resizing this causes an issue as it cannot determine type
91
+        if image.format:
92
+            f = image.format
93
+        else:
94
+            f = None
95
+
91 96
         if not image.mode.startswith('RGB'):
92 97
             image = image.convert('RGBA')  # Everything works better as RGB
93 98
 
94 99
         image.thumbnail((height, width), Image.ANTIALIAS)
95 100
 
96
-        # need to get extension from name due to bytes not having a name
97
-        # when resizing this causes an issue as it cannot determine type
98
-        try:
99
-            f = self.image_filename.split('.')[-1]
100
-        except:
101
-            if image.format:
102
-                f = image.format
103
-            else:
104
-                f = None
105
-
106 101
         breadcrumbs.record(message=f'Attempting to resize image with extension {f}', category='furryapp', level='info')
107 102
 
108 103
         resized_image = BytesIO()

Loading…
Cancel
Save