API Reference
Three tiers: a one-call convenience API, a low-level frame API for custom render loops, and a recording API for exports.
One-call API
asciify(source, canvas, options?)Convert an image (URL string, HTMLImageElement, HTMLVideoElement, or HTMLCanvasElement) and render onto a canvas. Handles loading, conversion, and rendering in one call.
asciifyGif(source, canvas, options?)Fetch and animate an animated GIF as ASCII art. Source can be a URL string or ArrayBuffer. Returns a stop() function to cancel the animation loop.
asciifyVideo(source, canvas, options?)Stream a video as live ASCII art in real time. Defaults to live streaming (instant start, unlimited duration). Pass preExtract: true for frame-perfect pre-extracted loops. Pass fitTo to auto-size the canvas to a container. Use trim: { start, end } to play only a slice of the video. Use chromaKey: true to remove green screens. Returns a stop() function.
live vs pre-extracted
Streams live from the playing video — instant start, constant memory, unlimited duration. Best for hero sections, loops, webcam.
const stop = await asciifyLiveVideo(src, canvas);Pre-extracts every frame before playing — loading delay, memory-intensive, 10s cap. Best for short clips where you need frame-perfect control.
const stop = await asciifyVideo(src, canvas);| asciifyLiveVideo | asciifyVideo | |
|---|---|---|
| Startup | instant | seconds (extracts first) |
| Memory | constant | grows with clip length |
| Max duration | unlimited | 10s cap |
| Seeking | ✕ | ✓ frame-perfect |
| Best for | loops · hero · webcam | short clips · scrub |
Shared options shape
{
fontSize?: number; // character size in px — default: 10
artStyle?: ArtStyle; // preset name — default: 'classic'
options?: Partial<AsciiOptions>; // any field from the full AsciiOptions object
// asciifyVideo only:
fitTo?: HTMLElement | string; // fit canvas to container + auto-resize
preExtract?: boolean; // pre-decode all frames (default: false)
trim?: { start?: number; end?: number }; // play a time slice (seconds)
onReady?: (video) => void; // called once when ready
onFrame?: () => void; // called after every frame
}ASCII Background API
asciiBackground(target, options?)Mount a live animated ASCII canvas behind any element. Target can be an HTMLElement or CSS selector string. The canvas is automatically sized, updated on window resize, and respects OS color scheme. Call destroy() to stop and remove the canvas.
Low-level API
Use these when you need full control — custom render loops, compositing, or embed code generation.
imageToAsciiFrame(source, options, targetWidth?, targetHeight?)Convert an image, video frame, or canvas to a single AsciiFrame. Reads pixel data including alpha. Returns a 2D cell grid indexed [row][col].
renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, time?, hoverPos?)Render a single AsciiFrame onto a 2D canvas context. Supports ASCII and Dots render modes, animation effects, and interactive hover. Optimized for 60+ FPS.
gifToAsciiFrames(buffer, options, targetWidth, targetHeight, onProgress?)Parse an animated GIF (ArrayBuffer) and convert every frame to ASCII. Handles GIF disposal methods, compositing, and frame timing. Capped at 300 frames.
videoToAsciiFrames(video, options, targetWidth, targetHeight, targetFps?, maxDuration?, onProgress?)Seek through a video element at the given FPS rate and convert each frame to ASCII. maxDuration limits extraction (default: 10s).
Snapshot API
Capture a single frame from a live ASCII canvas as a PNG, JPEG, or WebP.
captureSnapshot(canvas, options?)Capture a single frame from a canvas as a Blob. Supports png, jpeg, and webp formats with optional quality and scale.
snapshotAndDownload(canvas, options?)Capture a single frame and immediately trigger a browser download. Combines captureSnapshot with a temporary object URL.
import { captureSnapshot, snapshotAndDownload } from 'asciify-engine';
// Get a Blob you can upload or preview
const blob = await captureSnapshot(canvas, { format: 'png' });
const url = URL.createObjectURL(blob);
// Or trigger a download directly
await snapshotAndDownload(canvas, { format: 'jpeg', filename: 'my-art' });Data types
interface AsciiCell {
char: string; // Character mapped from luminance
r: number; // Red component (0–255)
g: number; // Green component (0–255)
b: number; // Blue component (0–255)
a: number; // Alpha channel (0–255)
}
type AsciiFrame = AsciiCell[][]; // 2D grid [row][col]
interface AsciiResult {
frames: AsciiFrame[];
cols: number;
rows: number;
fps: number;
}