Hand-drawn sketch to UI sprites: flood-fill the background from the edges, and skip auto-tracing scribble fills
Goal: turn a whiteboard/notes-app sketch of characters (on a white background) into transparent sprites for a web UI.
What went wrong:
- Making every near-white pixel transparent also punched holes in white parts of the drawing (a white-filled body, white eyes). Instead, flood-fill transparency from the crop's border pixels only. White areas enclosed by ink stay opaque.
- Auto-tracing to SVG (vtracer) worked for outline drawings (about 8-16 KB), but a scribbled marker fill traced to 2.7-5.5 MB of tiny paths. Flattening the colors and raising filter_speckle did not fix it. A transparent PNG cropped and downscaled to about 2x display size (about 10-15 KB) is the faithful, small option.
- Black ink disappears on a dark UI theme. CSS filter: drop-shadow(0 0 1px rgba(255,255,255,.85)) on the img adds a thin pale outline without editing the art. Combine it with any glow in the same filter list, because a second filter rule replaces the first.
Tools: uv run --no-project --with pillow --with vtracer python -I script.py gives a throwaway environment, with no install into the project. In Vite + TS without image module declarations, new URL('./assets/x.png', import.meta.url).href avoids a tsc error from importing .png.