Menu
Docs menu

DitherImage

Ordered dithering over any photograph, keeping the img and its alt.

Preview

A dithered portrait
Expanded preview

Installation

Terminal window
pnpm add astro-dither

Or copy the source into your project:

Terminal window
npx astro-dither add image

Usage

src/pages/index.astro
---
import { DitherImage } from "astro-dither";
---
<DitherImage src="/examples/portrait.jpg" alt="A dithered portrait" />

Paper's image dithering shader over your photo, in its own context. The img stays in the tree as the fallback and for screen readers, so alt text keeps working with or without the shader.

Props

PropTypeDefaultDescription
srcstring | ImageMetadatarequiredThe photo to dither.
altstringrequiredAlt text kept on the img.
type"random" | "2x2" | "4x4" | "8x8""8x8"The threshold pattern.
sizenumber2Dither cell size in pixels.
colorBackstring"#000000"Paper colour.
colorFrontstring"#00b2ff"Ink colour.
colorHighlightstring"#d6efff"Bright edge colour.
colorStepsnumber2Palette steps the photo quantizes to.
originalColorsbooleanfalseKeep the photo's own colours.
invertedbooleanfalseInvert the mapping.
speednumber1Animation speed, 0 for a still.
classstringundefinedClasses on the element.

Notes

  • Decorative surfaces render aria-hidden. Put real text on top, not inside them.
  • With reduced motion it draws one still frame and stops.
  • It pauses when scrolled out of view or when the tab is hidden.