Hiding a diagram's source in the pixels of its PNG

Draftably PNGs now carry their .draft source in a faint strip of pixels below the drawing, so a pasted image still opens as an editable diagram after a site strips its metadata. A sweep over every example picked the settings, and each product question made the strip smaller: from a 37 px band that survived JPEG to a 3% band that adds about 6 px.

November 29, 2026 · 8 min read · Feature · Draftably · draftably.dev ↗

Hiding a diagram's source in the pixels of its PNG

A Draftably PNG has always carried its .draft source in a metadata chunk. Paste the image back into the editor, or point the CLI at it, and you get the diagram, not a picture of it. That works until something strips the metadata. Plenty of places that pass images around keep the pixels and drop the chunks, and then the PNG is only a picture again.

The ask was a strip of pixels along one edge that holds the source, stays subtle, is not a QR code, and decodes from a pasted image. It shipped in byronwall/draftably#653, in draftably 0.19.0. Here is the bottom of a 2x export of the Order lifecycle example at real size. The strip is there.

The bottom of the Order lifecycle export at real size, with the strip along the bottom edge

Here is the left end of that same band, enlarged 4x with its contrast raised 25x:

The same band enlarged 4x with contrast raised 25x, so the modules show

Getting there took three rounds of measurement. Each round answered a product question, and each answer made the band smaller.

How much has to fit

The first step was to measure what the strip has to hold. The 25 files in examples/ ran from 643 to 1,464 bytes of source. With deflate at level 9, the median was 504 bytes. Brotli and a preset dictionary did better, but the browser's DecompressionStream('deflate-raw') takes no dictionary, so plain deflate is the baseline. That is about 5,000 bits once you add Reed–Solomon parity, so the strip can fix a damaged module instead of failing.

Drawings were 488 to 1,691 CSS px wide, median 1,143. So the question was how to fit about 5,000 bits along the bottom of a drawing about 1,100 px wide.

Five options came out of that:

OptionBand for the median sourceTrade-off
4-state postal bars, one row~50 pxEasy to decode, tall
1D binary bars~100 pxEasiest to decode, very tall
Multi-row band of small modules~22 pxMedium decode effort
The same band as a faint tint~45 pxNeeds bigger modules to survive JPEG
A short ID that points to a stored copy~6 pxNeeds a server and a privacy decision

The multi-row band was the only option that fit the median source in about 20 px on one edge. The stored copy is the smallest, but Draftably had no hosted store at the time. So the pick was a thin band of small binary modules, with a clock row and Reed–Solomon parity.

Then I made the product calls. The band goes on the bottom edge only, and it grows taller for a larger source instead of falling back to an ID. It should be as faint as the evals allow. It is on by default, with --no-source-strip in the CLI to turn it off. It decodes on paste in the editor and in the CLI.

The sweep

scripts/prove-strip.ts does the measuring. It draws every example with its band in Chrome at 2x, then resizes it and re-encodes it as PNG, JPEG and WebP in the page. Then it decodes the band from the pixels. Each setting gets a count out of 36 examples (the examples folder had grown by then) for each transform.

The first sweep tried to survive everything: lossy formats, resizes, and down to half size. The winner was 2.5 CSS px modules at 16% ink opacity, with a third of the band spent on parity. It decoded all 36 examples under PNG, JPEG at quality 60 to 85, WebP at 75, and resizes down to 0.75x. A selection of rows:

ModuleOpacityPNG 1xJPEG 60 1xWebP 75 1xJPEG 80 0.75xPNG 0.5x
2 px6%360000
2 px16%363535310
2.5 px10%3636343635
2.5 px16%3636363635
3 px10%3636263636

It worked, and you could see it. The band was 22.5 to 82.5 CSS px tall, median 37.5, plus a gap and a quiet zone. It looks like this:

The first band, at 2.5 px modules and 16% opacity: a grey textured strip under the drawing

Dropping lossy formats

Lossy formats do not matter for this. The cases I care about are PNG export, copy and paste, and screenshots of the drawing. So the second sweep was PNG only: every example, decoded after a smooth resize to each scale.

Two things changed. Opacity stopped being a limit at all. Lossless PNG decoded at 3% as well as at 8%. And the module size came from the smallest scale the band has to survive. A module has to stay at least about 1.25 image px, and band height grows with the square of the module size.

ModuleBand median / max2x1x0.63x0.5x
1.25 px8.75 / 18.75 px36000
2 px22 / 46 px3636360
3 px45 / 105 px36363633

2 px modules at 3% give a band about 22 px tall that survives a non-Retina screenshot. 1.25 px modules give about 9 px and cover 2x copies and Retina screenshots at 75% zoom or more.

Exact pixels

The third question was which case to ship first. I picked PNG export and copying that PNG to the clipboard. Both keep the export's exact pixels, so the band does not need to survive a resize at all. Modules can be sized in image pixels and snapped to the pixel grid.

At that point the settings got very small:

ExportModuleOpacityBand median / maxAdded height median / max
2x1 image px2%1.5 / 3.5 CSS px5.5 / 7.5 CSS px
2x2 image px3%5 / 11 CSS px13 / 19 CSS px
1x1 image px2%5 / 11 CSS px11 / 17 CSS px

The pick was 1 image px modules at 3% opacity with 10% parity. On a 2x export the band is 3 to 7 pixel rows, and the drawing grows by about 6 CSS px. It could not share the drawing's bottom padding, because 11 of the 36 examples draw labels there.

From the first sweep to the last, the band went from a median of 37.5 CSS px to about 6 px of added height. The encoding stayed the same. Module size, opacity and parity changed each time an answer narrowed what the strip has to survive, and the sweep made each answer cheap to check. Change the scope, rerun the script, and read the counts.

Shipping it

The export dialog got an "Also as a pixel strip" box, on by default, and its size line now shows the real PNG size. The CLI draws the strip on --png and --clipboard, and every command that reads a PNG falls back to it when the metadata is gone. Here is the round trip on the Order lifecycle example with Draftably 0.22.1. The scrubbed files have their text chunks deleted, the way a metadata-stripping host leaves them:

$ draftably inspect examples/order-lifecycle.draft --png order.png
Wrote order.png (2254×1182).
$ draftably format order-scrubbed.png | head -1
diagram "Order lifecycle" version=1
$ draftably inspect examples/order-lifecycle.draft --png order-plain.png --no-source-strip
Wrote order-plain.png (2254×1170).
$ draftably format plain-scrubbed.png
plain-scrubbed.png has no embedded draftably source. It was exported with --no-source, by another tool, or resized or recompressed by a host.

The strip costs 12 pixel rows on that export.

Codex reviewed the PR for three rounds. It found 22 problems: 19 were fixed and 3 were declined. One fix was a CRC-32 over the payload. Without it, a damaged strip could decode to a different valid codeword, which means the wrong diagram instead of no diagram. After that, a fuzz run flipped 1 to 40 modules in 1,500 strips and got 0 wrong sources: each one decoded right or returned nothing. The CLI round trip passed on all 36 examples at scales 1, 1.5, 2 and 3 (144 of 144). One test exists because a half-pixel shift at 2x once blurred every module.

What is still wrong with it

The review needed three rounds because the strip lives in too many places that have to agree, and the PR says so:

  • The pixel geometry is computed twice. The encoder draws the band as SVG rectangles, and then each renderer (the browser canvas, resvg in the CLI) rounds size and scale its own way. Half-pixel shifts, the blur at 2x, and the canvas-limit clamp all came from that gap. Drawing the band straight into the raster would remove it.
  • The decoder is built for a harder problem. Edge search, pitch search and noise floors exist to read resized and recompressed copies, which the first sweep needed. The shipped case is exact pixels, which needs a fixed marker at a known spot and a read at exact positions. Most of the cost and hang findings were in the search code.
  • Encoder and decoder each hold a copy of the format rules: minimum width, rounding, header layout. One layout function that both call, plus a round-trip test over random sizes, would stop a rule from changing on one side only.

None of that is done yet. Other limits: any resize, screenshot or lossy re-encode loses the strip, and then the metadata is the only copy. SVG and PDF exports do not carry it yet. And I have not tested real uploads to Slack or GitHub, so I can't say yet which hosts keep the pixels exactly.

The earlier sweeps already measured the next step. A band that survives a 2x copy and a Retina screenshot needs about 9 px; one that survives a 1x screenshot needs about 22 px.