fix img loading with transparency

This commit is contained in:
xander
2024-08-24 13:36:25 +02:00
parent 3b666a0b63
commit 413e4d898c
+10
View File
@@ -290,6 +290,16 @@ def load_image_with_orientation(path, mode="RGB"):
elif orientation == 8:
image = image.rotate(90, expand=True)
if image.mode == 'P':
image = image.convert('RGBA')
# Remove alpha channel if present
if image.mode in ('RGBA', 'LA'):
background = Image.new('RGB', image.size, (255, 255, 255))
background.paste(image, mask=image.split()[3]) # 3 is the alpha channel
image = background
# Convert to the desired mode
return image.convert(mode)