add support for LA mode images

This commit is contained in:
iou1name 2021-05-08 21:49:40 -04:00
parent 20d52f40c4
commit fb1d56d4c4

View File

@ -150,7 +150,10 @@ def alpha_composite(image, color=(255, 255, 255)):
"""
image.load() # needed for split()
background = Image.new('RGB', image.size, color)
background.paste(image, mask=image.split()[3]) # 3 is the alpha channel
if image.mode == "RGBA":
background.paste(image, mask=image.split()[3]) # 3 is the alpha channel
if image.mode == "LA":
background.paste(image, mask=image.split()[1]) # 1 is the alpha channel
return background
@ -169,6 +172,8 @@ def image_to_ascii(image=None, reverse=False, brail=False, color=None,**kwargs):
image = alpha_composite(image).convert("RGB")
if image.mode == "L":
image = image.convert("RGB")
if image.mode == "LA":
image = alpha_composite(image).convert("RGB")
image = scale_image(image)