INNER CODE UNIT · Python

icon_layers

WenyuChiou/awesome-agentic-ai-zh · scripts/build-banner.py:149

def icon_layers(locale, art):
    """Cover only an active icon, then move a clipped reuse of its exact pixels.

    At rest the entire layer disappears: the original image is untouched. A
    corner-sampled backing prevents a second, stationary icon showing beneath
    the moving copy. No new image payload, symbol library, or text is added.
    """
    from PIL import Image

    with Image.open(io.BytesIO(art)) as source:
        source = source.convert("RGB")
        parts = []
        for (name, (motion, _)), (x, y, w, h) in zip(ICON_MOTION.items(), ICONS[locale], strict=True):
            corners = [source.getpixel(point) for point in [(x,y),(x+w-1,y),(x,y+h-1),(x+w-1,y+h-1)]]
            backing = '#'+''.join(f'{int(median(channel)):02x}' for channel in zip(*corners))
            cx, cy = x+w/2, y+h if motion == "grow" else y+h/2
            parts.append(f'<g id="icon-{name}" class="icon-layer icon-layer-{name}" aria-hidden="true" data-motion="{motion}">'
                f'<defs><clipPath id="clip-icon-{name}"><rect x="{x}" y="{y}" width="{w}" height="{h}"/></clipPath></defs>'

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…