Terminal image rendering for Tinky.
tinky-image exports the Node runtime by default:
import { Image } from "tinky-image";
<Image src="./logo.png" width={40} alt="logo" />;Use the browser entry when your app is bundled with sharp-web:
import { Image } from "tinky-image/browser";Run the CLI demo:
npm run demo:cliFor a non-interactive smoke check that renders once and exits:
npm run demo:cli -- --snapshotRun the browser demo with tinky-web:
npm run demo:webBuild the browser demo bundle:
npm run demo:web:buildThe browser demo renders the shared Tinky showcase app inside an Xterm.js
surface provided by tinky-web, so the CLI and web examples stay aligned. Click
the terminal and use the left/right arrow keys or 1-4 to switch renderers.
Node supports:
- File paths such as
./logo.png - Absolute URLs such as
https://example.com/logo.png - Data URLs
Uint8ArrayBlob
Browser supports:
- Relative URLs such as
./logo.pngand/logo.png - Absolute URLs such as
https://example.com/logo.png blob:URLs- Data URLs
Uint8ArrayBlob
width and height are measured in terminal cells. Each accepts a number
of cells (width={40}) or a percentage of the terminal (width="50%"). The
resizeMode prop controls how the image is fit into that box and defaults to
"contain":
"contain"(default) — scale to fit entirely inside the box, preserving aspect ratio. If only one ofwidth/heightis given, the other is derived from the source aspect ratio; if both are given, the image fits inside the box."cover"— scale to fill the box, preserving aspect ratio. The image may overflow the box on one axis (the overflow is cropped by the terminal)."fill"— stretch to the exactwidth×height, ignoring aspect ratio."none"— use the image's natural cell size, ignoringwidth/height.
<Image src="./logo.png" width={40} resizeMode="contain" />Every mode except "none" clamps the rendered size to the current terminal
bounds.
Backends are auto-detected in this order:
kittyitermsixelhalfblockbrailleascii
You can override detection with the renderer prop.
kitty— terminal graphics protocol output for Kitty-compatible terminalsiterm— inline image protocol output for iTerm2-compatible terminalssixel— bitmap graphics output for terminals that support Sixelhalfblock— full-color text rendering using ANSI colors and the Unicode half-block character▄braille— monochrome high-density rendering using Unicode Braille patternsascii— plain character-art fallback for maximum compatibility