Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37f8aa1

Browse files
committed
[static] fix png transparency
1 parent ae08971 commit 37f8aa1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

element/plugins/static/static.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ def image_fit(self, request_handler, context, file):
7474
if not os.path.exists("%s/%s" % (path, filename)):
7575
image, format = self.fix_orientation(Image.open(file))
7676

77-
# ImageOps compatible mode
78-
if image.mode not in ("L", "RGB"):
79-
image = image.convert("RGB")
77+
image = self.fix_color(image, format)
8078

8179
request_handler.send_file_header(file)
8280

@@ -102,9 +100,7 @@ def image_resize(self, request_handler, context, file):
102100
if not os.path.exists("%s/%s" % (path, filename)):
103101
image, format = self.fix_orientation(Image.open(file))
104102

105-
# ImageOps compatible mode
106-
if image.mode not in ("L", "RGB"):
107-
image = image.convert("RGB")
103+
image = self.fix_color(image, format)
108104

109105
if image.size[0] > w:
110106
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):
125121

126122
return path
127123

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+
128131
def fix_orientation(self, image):
129132

130133
try:

0 commit comments

Comments
 (0)