# Pixel grid from an image

Pick an image and the tool averages it down to a grid of a few columns, cuts its colours to a small
palette, then draws what falls between two colours with a dither. What you copy is a ` ```pixel `
fence, the same text as a grid drawn by hand: retouch it, version it, translate its `alt`.

<PixelFromImage />

The image is read by your browser and never leaves the page. Récit carries no image decoder of its
own: the decoding happens in Chromium, the reduction in plain TypeScript (`reducePixelImage` of
`@recit/components/pixel`), the same for every input.

## Settings

| Setting | What it does                                                                                    |
| ------- | ----------------------------------------------------------------------------------------------- |
| Columns | Width of the grid, 4 to 128; the rows follow the ratio of the image, never past 128             |
| Colours | Size of the palette, 2 to 16, found by median cut; fewer when the image has fewer               |
| Dither  | `None` (flat areas), `Floyd–Steinberg` (spreads the error, soft) or `Ordered (Bayer)` (pattern) |

A cell whose pixels are mostly transparent stays transparent (`.` in the legend). The colours are
keyed `a`, `b`… from the darkest, as hex colours: replace one by a theme token (`text`, `accent`…)
in the legend to make the picture follow the site's theme in light and dark mode.

## From code

```ts
import { pixelToFence, reducePixelImage } from "@recit/components/pixel";

// data: the RGBA bytes of a canvas, getImageData(0, 0, width, height).data
const grid = reducePixelImage({ width, height, data }, { columns: 48, colors: 6, dither: "bayer" });
const fence = pixelToFence({ ...grid, alt: "Lorem harbour at dusk" });
```

A grid stays small on purpose: a photo becomes a picture of a few hundred cells, not a copy of the
photo. For a real sprite sheet drawn by hand, see [import a sprite sheet](/pixel-import).
