Google Lens-style "translate what's in the photo and keep the layout" is a genuinely fun problem. Here's the shape of a version that does the heavy lifting on the client and only calls a model for the part a model is actually good at.
The pipeline
- Vision model → structured blocks. Send the image to a multimodal model and ask for strict JSON: for each text block, a bounding box normalized to 0–1000, the original text, the translation, the glyph color, and a bold flag. Keeping the model's job narrow (read + translate + locate) makes the output much more reliable than asking it to "edit the image."
- Snap the boxes to the real ink. Model boxes are approximate — they drift by half a line. On the client, take the box as a hint, find the dominant background color inside it, build an ink mask, and discard any ink touching the search border (that's a banner edge or a neighbouring line). What's left, enclosed by background, is the true text extent.
- Erase the original text. For flat or gradient backgrounds, a Coons-patch fill interpolated from the four edges is seamless and instant. For busy photo backgrounds, an inpainting model (MI-GAN) fed a mask of only the glyph pixels — dilated to catch the anti-aliasing and shadow — removes the text without smudging.
- Redraw the translation. Match the measured color, infer the original font size by comparing the source text's rendered ink-height to its height on the image, auto-fit, and re-wrap.
The gotcha worth knowing
Running ONNX inference on the main thread freezes the whole tab for the duration — I measured a ~15 second lock on background inpainting. Setting ort.env.wasm.proxy = true silently fell back to the main thread in a Vite/ESM build. The fix that actually worked was a dedicated Web Worker that imports onnxruntime-web, caches models in Cache Storage, and transfers buffers both ways. Main-thread freeze dropped from ~15s to ~0.5s.
Try it
A free, no-sign-up version is live at roodytools.com/translate-image — drop in a screenshot or a photo of a menu/sign and it replaces the text in place, then lets you zoom in to inspect and tap any block to fix the wording.
More browser-only tools at roodytools.com. Questions welcome.

