The bug report fits in one line: the text looks crisp in the editor and soft in the exported PNG. A quick fix is to take whatever the preview canvas holds and scale it up on the way out. This test put that fix next to the alternative: one Apple-silicon Mac, desktop Chromium, one run per case. The sample is a homemade text line, bold 28px, black on white, logical size 400×100, target file 800×200. Upscaling the preview bitmap gave an edge transition of 5.98 px. Drawing the text again at 800×200 gave 1.641 px. An 8x supersampled reference came out at 1.768.
Both metrics are custom. Edge transition width is the average length, row by row, of runs of pixels whose gray value sits between 32 and 223, so closer to the reference means a more faithful edge. Error is the mean absolute gray difference from the reference on a 0 to 255 scale. Neither is a standard, just two numbers I could compare without arguing about taste.
Upscaling the preview made edges 3.6 times wider
In path A the backing store equals the CSS size, 400×100, gets exported with toDataURL, and a bilinear resize takes it to 800×200. Edge width 5.98, error 4.759, identical at DPR 1, 2 and 3, because nothing in that path asks about the screen. Path C ignores the screen and draws the text again on an 800×200 canvas: 1.641 and 1.603. A's edge is about 3.6 times as wide as C's. I spent three years on codecs before moving to graphics tools, and the oldest lesson from scaler work applies: an upscaler cannot recover edge detail that was never rasterized.
The preview can have the same disease on its own. With the canvas at 400×100 and CSS stretching it to 800×200, the on-screen edge in device pixels measured 5.99 at DPR 1, 11.262 at DPR 2 and 16.756 at DPR 3. Sizing the backing store by DPR brought those to 1.641, 1.873 and 1.639. A real bug, but a preview bug, and its fix belongs in the preview path.
Sizing the export by DPR fixed only one screen
Path B is the common DPR fix: multiply the canvas by devicePixelRatio, call ctx.scale(dpr, dpr), export. At DPR 2 it produced 800×200 and matched C exactly. At DPR 1 it collapsed into path A, so anyone on an ordinary monitor still downloaded a 1x file. At DPR 3 it produced 1200×300. Scaled down to 800×200, that one had the lowest error of every run, 1.46, but an edge width of 2.517, wider than the reference. My guess is the downscale filter softened edges while the extra samples pulled the average closer. Which matters more for text people actually read is open; no viewing test was run. Without that downscale, the DPR 3 user ships a third file size. One document, three assets, decided by whose laptop pressed the button.
fillText output followed canvas pixels only
Paths A and C produced pixel-identical files at DPR 1, 2 and 3, so the rasterized text depended only on canvas pixels. The maximum red-blue difference was 0 in every export: grayscale antialiasing, no color fringes. A dense screen only makes an underprovisioned canvas easier to see, which is the 5.99 against 11.262 above. Safari, Firefox, Windows ClearType, imageSmoothingQuality, OffscreenCanvas and the scale option in html2canvas are untested.
Export should depend on the document and the target size only
So the contract is two functions. Preview takes the document, the screen and a performance budget, and may follow devicePixelRatio or drop resolution while the user drags. Export takes the document and a target size, nothing else. Codecs draw the same line: what a decoder outputs does not depend on the display that shows it.
One shipping editor was checked against this contract: ImgIng https://imging.ai/ . In this test a 1024×1024 PNG with two lines of text was exported from its online editor at screen scale 1 and then 2. Both files stayed 1024×1024 and were pixel-identical. Its site says preview uses adaptive resolution and export recomposites at the original canvas size. The online editor isn't a part I worked on, so what I can vouch for is the site's description plus one test, not its internals. The base image is a CC0 photo from Wikimedia Commons by Bonnie Moreland; the text is homemade.
A pure export path is also testable: render one document at DPR 1, 2 and 3 and assert identical pixels. Path C passed that check in this run; path B can't by design. Fonts may rasterize differently across engines, so I'd keep one golden file per engine; only Chromium was tested here. If you own an export button, search the export code for devicePixelRatio, then export one document at DPR 1 and 2 and compare. A hit or two different files means the user's screen is leaking into the asset.
Top comments (0)