Building a 100% Browser-Local Photo-to-Sticker Maker with ONNX Runtime Web, Polygon Nesting & 1:1 Print Calibration

2026-12-01来源 dev.toEnglish

Most online sticker makers follow the same pattern: upload your personal or family photo to a cloud server, wait in a queue, and pay to remove a watermark.

While building PhotoToSticker.ai, I wanted to see how far we could push a 100% browser-local workflow—where photos never leave the user's device, transparent PNGs export without watermarks, and physical print sheets actually come out at the exact millimeter size you typed.

Here are the three hardest technical problems I ran into and how I solved them in plain browser JavaScript.

1. Running AI Background Removal Locally with Zero Server Queue

Instead of paying for GPU inference servers (and forcing users to upload private pet or baby photos), PhotoToSticker runs the open-source ORMBG segmentation model directly inside the browser via ONNX Runtime Web.

  • First-load trade-off: The browser downloads ~34.7 MB of quantized ONNX model and runtime files once and caches them locally.
  • Payoff: Every sticker after the first runs in seconds with zero cloud queues, works on both desktop and mobile browsers (including native iPhone HEIC in Safari), and guarantees that user photos never touch a server.
  • Manual fallback: Automatic segmentation still struggles on flyaway hair, whiskers, or low-contrast backgrounds, so I paired the model with a local canvas Erase / Restore brush editor (with a press-and-hold magnifier on phones) and a free desktop 1024 high-precision pass.

2. Fitting More Irregular Stickers on an A4 Sheet (Polygon Nesting + Dual Cut Lines)

A naive rectangular grid wastes a ton of expensive vinyl sticker paper whenever stickers have irregular silhouettes (like a jumping corgi or a portrait).

In the browser-side PDF generator (pdf-lib), I implemented a two-layer Contour cut workflow:

  1. Moore boundary tracing & hull simplification extract the tight white-border contour of each transparent sticker.
  2. Rotation-aware polygon nesting interlocks irregular shapes at 0°/90°/180°/270° with a minimum 5 mm scissor gap—often fitting 30–50% more stickers on a single A4 sheet compared to a grid.
  3. Dual vector cut lines draw a light outer rough-cut polygon (for fast sectioning off the sheet) plus a fine inner contour hugging the white border.

I documented the full layout breakdown here: How to Fit More Stickers on an A4 Sheet.

3. Solving the "How Big Is 50 mm Really?" Problem on Any Monitor

Browsers intentionally hide your monitor's physical PPI to prevent fingerprinting. That means 96 CSS px = 1 inch can easily be off by 10%–15% depending on whether you are on a 24" 1080p monitor, a 27" 2K screen, or a Retina laptop.

To keep people from wasting sticker paper:

  • In the exported PDF: We set PrintScaling.None in the PDF viewer preferences and print an explicit "Print at 100% (Actual size)" reminder on Page 1, plus an optional 50 × 50 mm verification square.
  • On screen before printing: We built a full-screen 100% Real-Size Sheet Preview paired with a 5-second bank card calibration (holding a standard 85.6 × 54 mm ISO card flat against a dashed box and dragging a slider, saved to localStorage). Once calibrated, on-screen scale gets within ~±1% accuracy.

More details on the calibration workflow: How to Preview Actual 1:1 Sticker Size Before Printing.

Try It Out

The core maker (local AI cutout, Erase/Restore brushes, Plain/Holographic/Rainbow finishes, 1024 px watermark-free transparent PNGs, and clean A4/US Letter print PDFs) is completely free with no sign-up at phototosticker.ai.

If you have built browser-local ONNX or client-side PDF tools, I'd love to hear how you handle mobile Safari memory limits and model caching!

原文:https://www.a8q9.cn/en/article/building-a-100-browser-local-photo-to-sticker-maker-with-onnx-runtime-web-polygo-3d8e6d.html

相关文章