Handle grayscale images in expand2square (#97)

This commit is contained in:
isaac-vidas
2024-01-24 19:23:11 -05:00
committed by GitHub
parent d3fc86a43e
commit 0c457bae8f

View File

@@ -163,7 +163,9 @@ def expand2square(pil_img, background_color):
width, height = pil_img.size
if width == height:
return pil_img
elif width > height:
if pil_img.mode == "L":
pil_img = pil_img.convert("RGB")
if width > height:
result = Image.new(pil_img.mode, (width, width), background_color)
result.paste(pil_img, (0, (width - height) // 2))
return result