Browse Source

Fix issue with determining image format.

refactor
Syfaro 7 months 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
         """Resize image to specified height and width with antialiasing"""
82
         """Resize image to specified height and width with antialiasing"""
83
         image = Image.open(self.image_bytes)
83
         image = Image.open(self.image_bytes)
84
 
84
 
85
-        print('attempting image resize')
86
-
87
         if image.height <= height and image.width <= width:
85
         if image.height <= height and image.width <= width:
88
             self.image_bytes.seek(0)
86
             self.image_bytes.seek(0)
89
             return self.image_filename, self.image_bytes
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
         if not image.mode.startswith('RGB'):
96
         if not image.mode.startswith('RGB'):
92
             image = image.convert('RGBA')  # Everything works better as RGB
97
             image = image.convert('RGBA')  # Everything works better as RGB
93
 
98
 
94
         image.thumbnail((height, width), Image.ANTIALIAS)
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
         breadcrumbs.record(message=f'Attempting to resize image with extension {f}', category='furryapp', level='info')
101
         breadcrumbs.record(message=f'Attempting to resize image with extension {f}', category='furryapp', level='info')
107
 
102
 
108
         resized_image = BytesIO()
103
         resized_image = BytesIO()

Loading…
Cancel
Save