INNER CODE UNIT · Python

head_center_fraction

utopia-rise/godot-jvm · logo/export.py:231

def head_center_fraction(logo):
    """Vertical center of the mascot's head as a fraction of the logo height. The smoke above
    the cup is thin, so the head starts at the first row whose opaque span is wide (the cup rim)."""
    alpha = logo.getchannel('A').point([255 if v > 40 else 0 for v in range(256)])
    for y in range(logo.height):
        box = alpha.crop((0, y, logo.width, y + 1)).getbbox()
        if box and box[2] - box[0] > logo.width * 0.3:
            return (y + logo.height) / 2 / logo.height
    sys.exit('Could not locate the mascot head in highres/logo-1024.png')

def paste_logo(bg, logo, head_center, x, y):
    """Paste the logo so the mascot's head (ignoring the smoke) is centered on (x, y)."""
    logo = logo.resize((int(logo.width * LOGO_HEIGHT / logo.height), LOGO_HEIGHT), Image.Resampling.LANCZOS)
    y -= int((head_center - 0.5) * LOGO_HEIGHT)
    shadow = Image.new('RGBA', (logo.width + 200, logo.height + 200), (0, 0, 0, 0))
    tint = Image.new('RGBA', logo.size, (5, 3, 20, 190))
    tint.putalpha(logo.getchannel('A'))
    shadow.alpha_composite(tint, (100, 130))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…