skip to content
mpkcn

~/components/ascii-image

ASCII Image

An image that starts as a wall of flickering code glyphs and decodes into the real picture in a left-to-right sweep.

Mountains at dusk, flat illustration

Installation

terminal
npx mpkcn add ascii-image
deps:none beyond react· tested with react@19.3.0

Usage

Give it an image and a size:

tsx
import { AsciiImage } from "@/components/mpkcn/ascii-image";

export function Portrait() {
  return <AsciiImage src="/me.jpg" alt="Portrait of the author" className="aspect-[4/5] w-64" />;
}

Right after hydration the picture is covered by a wall of glyphs (01<>/{}$#=+*) in the blue accent. When the frame scrolls into view, each cell flickers, flashes bright and drops away in a noisy left-to-right sweep (1.8s), until only the photo is left. The canvas is then removed.

Examples

Bigger glyphs

Mountains at dusk, flat illustration

Custom characters, start on load

tsx
<AsciiImage src="/cover.png" alt="Album cover" chars="░▒▓█" trigger="mount" delay={600} className="size-72" />

Wait for an intro

play={false} keeps the code wall up until you flip it, for example when a Boot Screen ends:

tsx
<AsciiImage src="/me.jpg" alt="Portrait" play={booted} className="aspect-[4/5] w-64" />

Props

PropTypeDefaultDescription
srcstring—Image URL.
altstring—Alt text for the image.
trigger"mount" | "view""view""view" decodes when the image scrolls into view; "mount" right after load.
playbooleantrueHold the code wall until this turns true.
charsstring"01<>/{}$#=+*"Characters the code wall is made of.
cellnumber14Size of one glyph cell in px.
delaynumber300Milliseconds to wait, wall fully shown, before decoding starts.
durationnumber1800Milliseconds the left-to-right decode takes.
skipOnLowPowerbooleantrueSkip the effect on weak devices (4 cores or fewer, 4 GB memory or less, or Save-Data on).
ignoreReducedMotionbooleanfalseAnimate even when the user prefers reduced motion. Only use it behind an explicit action, like a "play anyway" button.
onDone() => void—Called once when the decode finishes, or right away when it is skipped.
classNamestring—Classes for the frame. Set its size here, e.g. "aspect-[4/5] w-64".

Accessibility

  • The real <img> with your alt text is always in the page, and it is what the server renders: without JavaScript you simply see the photo.
  • The glyph canvas is decorative (aria-hidden) and is removed once the decode ends.
  • Under prefers-reduced-motion: reduce, and on low-power devices, the effect is skipped and the photo shows straight away.
  • Glyph colors are read from --mpk-bg, --mpk-blue and --mpk-ink when it starts, so it matches the current theme.