@@ -74,9 +74,7 @@ def image_fit(self, request_handler, context, file):
74
74
if not os .path .exists ("%s/%s" % (path , filename )):
75
75
image , format = self .fix_orientation (Image .open (file ))
76
76
77
- # ImageOps compatible mode
78
- if image .mode not in ("L" , "RGB" ):
79
- image = image .convert ("RGB" )
77
+ image = self .fix_color (image , format )
80
78
81
79
request_handler .send_file_header (file )
82
80
@@ -102,9 +100,7 @@ def image_resize(self, request_handler, context, file):
102
100
if not os .path .exists ("%s/%s" % (path , filename )):
103
101
image , format = self .fix_orientation (Image .open (file ))
104
102
105
- # ImageOps compatible mode
106
- if image .mode not in ("L" , "RGB" ):
107
- image = image .convert ("RGB" )
103
+ image = self .fix_color (image , format )
108
104
109
105
if image .size [0 ] > w :
110
106
image = ImageOps .fit (image , (w , int (w * image .size [1 ] / image .size [0 ])), Image .ANTIALIAS )
@@ -125,6 +121,13 @@ def make_temp_path(self, path):
125
121
126
122
return path
127
123
124
+ def fix_color (self , image , format ):
125
+ # ImageOps compatible mode
126
+ if format in ["JPEG" ] and image .mode not in ("L" , "RGB" ):
127
+ image = image .convert ("RGB" )
128
+
129
+ return image
130
+
128
131
def fix_orientation (self , image ):
129
132
130
133
try :
0 commit comments