INNER CODE UNIT · Python
badge_row
utopia-rise/godot-jvm · logo/export.py:175
def badge_row(fnt, height=100, icon_box=50, gap=20, pad_x=36, icon_gap=20):
"""Render the language badges into a tightly cropped layer."""
row = Image.new('RGBA', (CANVAS_W, height), (0, 0, 0, 0))
x = 0
for name, label in LANGUAGES:
with Image.open(LANGUAGE / f'{name}.png') as image:
icon = image.convert('RGBA')
icon = icon.crop(icon.getbbox())
icon.thumbnail((icon_box, icon_box), Image.Resampling.LANCZOS)
white = Image.new('RGBA', icon.size, (255, 255, 255, 255))
white.putalpha(icon.getchannel('A'))
width = int(pad_x * 2 + icon_box + icon_gap + fnt.getlength(label))
badge = Image.new('RGBA', (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(badge)
draw.rounded_rectangle((0, 0, width - 1, height - 1), radius=height // 2,
fill=(130, 100, 240, 42), outline=(165, 140, 255, 170), width=3)
badge.alpha_composite(white, (pad_x + (icon_box - white.width) // 2, (height - white.height) // 2))
draw.text((pad_x + icon_box + icon_gap, height / 2 + 2), label, font=fnt, fill=(244, 245, 255, 255), anchor='lm')