Skip to documentation content

Pixelate

Pixelate an image or procedural field, with optional glitch bursts, channel split, scanlines, and a sharp lens under the pointer.

pixelate-demo

Overview

Pixelate samples its source once per block, so the picture reads as large pixels. On top of that sit independent layers you can mix:

  • Glitch fires short random bursts: bands of rows shift sideways, the red and blue channels split, and a few blocks invert. At 0 the effect is perfectly still.
  • Color split keeps a constant red and blue offset, like a misaligned print or a cheap lens.
  • Scanlines darken alternate lines for a display look.
  • Color levels posterizes each channel to a small palette.
  • Reveal sharpens a soft circle under the pointer, so people can look through the pixels.

Without src, Pixelate works on a slow procedural field.

The playground uses free Unsplash photographs by Martin Péchy and Marc Wieland.

Installation

npm install honestui

Usage

Image with a reveal lens

import { Pixelate } from "honestui/shaders"

<Pixelate
  alt="Blue and orange apartment buildings against a clear sky."
  className="h-80 rounded-xl"
  pixelSize={14}
  reveal
  src="https://images.unsplash.com/photo-1553933420-77617bac448e?auto=format&fit=crop&w=1600&q=85"
/>

Glitch

<Pixelate className="h-80 rounded-xl" pixelSize={6} glitch={0.5} colorSplit={1.5} scanlines={0.3} />

Remote image hosts must allow cross-origin use so WebGL can read the pixels. Glitches need a render loop, so a Pixelate with glitch above 0 keeps drawing while it is visible.

Accessibility

Glitch bursts flash and jump. Keep glitch low on large areas, never pair it with content people must read, and avoid it entirely near text or controls; rapid flashing can trigger seizures or migraines. When the user prefers reduced motion, glitches and the procedural field stop and one still frame shows. The pointer reveal is optional decoration and has no keyboard equivalent, so do not hide information behind it.

In image mode, write alt text for the image's purpose, or an empty string when it is decorative. The original image shows until the canvas is ready and remains in the accessibility tree afterwards.

API Reference

PropTypeDefaultDescription
srcstring–Image to pixelate. Omit it to use the procedural field.
altstring–Alternative text for the image. Required with src; use an empty string for decorative images.
pixelSizenumber10Block size in CSS pixels. 1 leaves the source sharp.
glitchnumber0Glitch intensity from 0 to 1.
glitchRatenumber1How often bursts fire.
colorSplitnumber0Constant red and blue channel offset in CSS pixels.
scanlinesnumber0Scanline darkness from 0 to 1.
colorLevelsnumber0Levels per channel. 0 keeps full color.
revealbooleanfalseSharpens the area around the pointer.
revealRadiusnumber120Radius of the sharp area in CSS pixels.
animatedbooleantrueAnimates the procedural field. Images stay still apart from glitches.
speednumber0.6Speed of the procedural field.
sourceColors[string, string, string]–Three colors of the procedural field.
pausedbooleanfalseRenders one still frame without glitches.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content layered above the effect.