DEV Community

yang li
yang li

Posted on

Making an AI cat sticker maker that keeps the same cat across poses

Making an AI cat sticker maker that keeps the same cat across poses

I built an AI cat sticker maker — you upload one photo of your cat and it returns six stickers in different poses (happy, crying, sleepy, shocked…) that still look like your cat. Here are the three problems that actually took work, and how I solved them.

1. Identity consistency across poses

The naive approach — prompt the model six times with "a cute cat sticker, happy / sad / …" — gives you six different cats. The fix was a two-stage pyramid:

  1. Generate one canonical reference from the uploaded photo, with an explicit identity checklist in the prompt (fur color, markings, face structure, eye/ear/nose shape, proportions).
  2. Condition every pose on that canonical, repeating the "must be the SAME individual cat" constraint.

Randomizing which six poses to draw is done in backend code (Fisher–Yates over a pose pool), not left to the model — that keeps the workflow deterministic on retries.

2. Background removal on white cats

Stickers need a transparent cut-out. I first wrote a classic chroma-key pipeline (flood-fill from the edges, despill, etc.). It works — until you get a white cat on a white background, where the fur, the whiskers and the background are all nearly the same color. That's an ill-posed problem for color-based keying.

Switching to a neural matting model (BiRefNet) was the single biggest quality jump: it segments the subject semantically, so white fur, fuzzy edges and thin whiskers all come out clean. The old algorithm stays as a fallback if the matting call fails.

3. A die-cut border that ignores whiskers

Printable stickers want a clean, constant-width white border. A naive dilation of the silhouette gives a border whose width varies with local curvature — it looks amateurish. And thin whiskers make the cut line spiky and impossible to actually cut.

The fix: compute a Euclidean distance transform of the silhouette and threshold it, so the border is mathematically the same width everywhere. Before that, a small blur+threshold smooths thin whiskers out of the cut outline (they stay inside the sticker, they just don't dictate where you cut).

Stack notes

The whole thing runs on Cloudflare Workers (Next.js via the OpenNext adapter), with the image pipeline in a Workflow. The tight per-step CPU budget on Workers was a real constraint — I ended up hand-rolling a fast PNG encoder and doing all the matting math on typed arrays.


If you want to see the output, you can try the custom cat stickers generator — it's free to generate and preview. I'd love feedback on the sticker quality, especially edge cases (long-haired cats, unusual markings).

Top comments (0)