Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Building a Privacy-First Photo-to-DMC Cross-Stitch Chart Compiler in Pure JavaScript

If you have ever dropped a family portrait or pet photo into a quick image-to-grid script, you know how fast the output falls apart: skin tones turn weirdly greenish or muddy gray, skies break into 90-color "confetti" st

Building a Privacy-First Photo-to-DMC Cross-Stitch Chart Compiler in Pure JavaScript

StitchGrid Studio browser-local DMC cross-stitch chart compiler

If you have ever dropped a family portrait or pet photo into a quick image-to-grid script, you know how fast the output falls apart: skin tones turn weirdly greenish or muddy gray, skies break into 90-color "confetti" stitches, and you end up with a pattern nobody actually wants to stitch.

Most naive converters treat the problem as simple RGB Euclidean distanceβ€”pick the closest hex value in sqrt(dRΒ² + dGΒ² + dBΒ²) against a floss table and call it a day. The catch is that human vision does not measure color difference uniformly in sRGB space, and unconstrained per-pixel matching creates isolated single-stitch noise everywhere.

Even worse, many online pattern makers force you to upload personal family photos to a remote server just to quantize a grid.

That is why I built StitchGrid Studio at LessworkApps: a 100% browser-local photo-to-DMC cross-stitch chart compiler written in pure JavaScript, keeping every pixel inside your tab from image sampling through vector PDF export.

Here is how the three core parts of the compiler work.

1. Perceptual Color Mapping to Authentic DMC Floss Swatches

Converting an image to embroidery thread starts with two constraints: you only have real-world DMC cotton floss hex swatches (~450+ standard shades), and human eyes are far more sensitive to lightness and skin-tone hue shifts than raw RGB channel deltas.

Instead of matching raw RGB triples, the compiler downsamples the source image cleanly onto the target stitch grid using an offscreen HTML5 <canvas>, converts each sampled cell into a perceptual color space (CIE Lab / weighted perceptual delta-E), and measures perceptual distance against pre-converted DMC swatch coordinates.

Matching in perceptual space prevents high-saturation reds or greens from pulling neutral skin shadows off-hue, keeping transitions natural even with modest floss counts.

2. Constraining Palette Size (12–45 DMC Shades) & Skein Math (14ct / 16ct / 18ct)

Even with perceptual distance, matching against all ~450 DMC colors creates unstitchable confettiβ€”dozens of skeins needed for just three or four stray stitches each.

To keep charts practical, the compiler runs a two-stage palette reduction:

  1. Frequency-Weighted Palette Selection: Clusters dominant and perceptually distinct shades, then prunes rare outlier colors and re-maps their cells to the nearest surviving palette member inside a configurable 12–45 DMC shade budget.
  2. Skein & Fabric Estimation: Once stitch counts per DMC code are finalized, the estimator computes thread consumption across 14ct, 16ct, and 18ct Aida fabric counts (accounting for stitch size, 2-strand coverage, and standard ~8 m / 8.7 yd skein lengths plus waste margin), giving stitchers a shopping list with exact skein counts before threading a needle.

3. Local Multi-Page 10Γ—10 Tiled Vector PDF Export

Rasterized pattern PNGs turn blurry the moment a stitcher zooms in on a tablet or prints pages on letter paper.

Instead, StitchGrid Studio emits a pure-JS vector PDF locally in the browser:

  • Multi-Page 10Γ—10 Tiled Grids: Large charts split cleanly across tiled pages with bold 10Γ—10 major gridlines, row/column ruler coordinates, and clear overlap indicators.
  • B&W Symbol + Color Views: Each DMC thread gets a high-contrast geometric glyph so stitchers can print crisp black-and-white symbol charts or use colored symbol cells on an iPad.
  • Complete DMC Legend: Pairs every symbol with its DMC number, shade name, stitch count, and skein total.

Because the entire pipeline runs via Canvas 2D + client-side Blob generation, family and pet photos never touch a server.

Try StitchGrid Studio Free in Your Browser

Everything runs locally in your browser with zero account required:

  • Try StitchGrid Studio free (up to 60 stitches wide with zero login): https://lessworkapps.com/stitchgrid
  • 48s live walkthrough video: https://youtu.be/cjhF1OH79WI
  • Optional one-time Pro pass: Unlocks full-scale high-stitch-count patterns and full commercial exports ($24.99 regular, or 50% off -> $12.49 one-time with launch code LAUNCH50β€”zero monthly subscription).

If you are working on browser-side color quantization or perceptual Lab/Delta-E matching in JS, happy to compare notes in the comments!

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.