Always convert image to RGB format

Closes #13206
This commit is contained in:
Cédric Krier committed 2024-04-20 12:26:21 +02:00
1 parent 3800523d11
commit cd41ab4c5e
2 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -171,8 +171,8 @@ class ImageMixin(_ImageMixin):
data = io.BytesIO()
img = PIL.Image.open(io.BytesIO(image))
img.thumbnail((SIZE_MAX, SIZE_MAX))
if img.mode in {'RGBA', 'P'}:
img.convert('RGBA')
if img.mode != 'RGB':
img = img.convert('RGB')
background = PIL.Image.new('RGBA', img.size, (255, 255, 255))
background.alpha_composite(img)
img = background.convert('RGB')
+2 -2
View File
@@ -128,8 +128,8 @@ class Avatar(ImageMixin, ResourceMixin, ModelSQL):
(height + size) // 2))
if size > 2048:
img = img.resize((2048, 2048))
if img.mode in {'RGBA', 'P'}:
img.convert('RGBA')
if img.mode != 'RGB':
img = img.convert('RGB')
background = Image.new('RGBA', img.size, (255, 255, 255))
background.alpha_composite(img)
img = background.convert('RGB')