Install
Install with PiG
pig install npm:pi-img-previewInstall with Pi
pi install npm:pi-img-previewPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./dist/index.js"
]
}README
Written by the package's publisher, shown as published in version 0.1.1 (README.md). PiG does not review it.
pi-img-preview
English · 한국어 · 日本語 · 简体中文 · Français · Español · Português (Brasil)
Preview local images above the Pi coding agent editor without a terminal graphics protocol. Image paths in your draft appear as labels on a single row. Press F8 to open a preview, or click a label in Pi's fullscreen mode.
Status: 0.1.1 is published on npm. Targets macOS and Linux with Node.js 22.19+; developed against Pi 1.5.2. Native Windows paths are not supported by this extension.
Install
pi install npm:pi-img-preview
Remove it with pi remove npm:pi-img-preview.
Try from source
In the source directory, run:
npm ci --ignore-scripts
npm run build
pi -e ./dist/index.js
-e loads the extension for this run only. To keep the checkout installed, build it first, then use pi install /absolute/path/to/checkout. Remove it with pi remove /absolute/path/to/checkout. Restart Pi after rebuilding or upgrading: /reload on the tested Pi version can keep older imported modules in memory.
Use it
- Paste an image with Pi's existing Ctrl+V, drop a local image file into the terminal, or type its path.
- Press F8 to open the first preview. Press it again for the next image, and once more after the last image to close it. On keyboards with media keys, use Fn+F8 if needed.
- In fullscreen mode (
pi --tui-mode fullscreen), click a label to open or close its preview. If there are more labels offscreen, click←or→at the edge of the row to see them. In regular mode, use F8.
Illustration of the controls, with the image area omitted:
[expanded image]
▾ landscape.png ▸ portrait.png ▸ with spaces.png ▸ tiny.png
Labels follow draft order and stay on one row, even when you have to page through them. Only one preview can be open at a time:
[expanded image]
← ▸ portrait.png ▾ with spaces.png →
Up to four images get labels. When F8 opens a preview, its label scrolls into view if needed. The preview fits the available width and leaves room for the editor and footer. Removing a path or submitting the draft clears its preview. The extension never rewrites your draft or submission. It does not read the clipboard or attach images to model requests.
Path examples
./screenshot.png
@./photo.jpg
"/Users/me/Pictures/photo with spaces.png"
/Users/me/Pictures/photo\ with\ spaces.png
~/Pictures/animation.gif
file:///Users/me/Pictures/photo%20one.webp
Compare ./overview.png, then ./detail.png.
'./overview.png''./detail.png'
Relative paths are resolved from the session's working directory. When writing a path with spaces in a sentence, quote the whole path or escape each space with \. Unquoted absolute paths from Finder also work on a line by themselves. The extension does not run shell commands or expand variables or globs. If an image name ends in punctuation, the literal path is tried first. Only a missing path can fall back to the unpunctuated name.
For the specific comappleCloudDocs spelling sometimes produced by a Finder drop, the preview may use the existing file under com~apple~CloudDocs. This recovery only affects the preview. Correct the path in your draft if Pi needs to read that file after submission. Remote URLs are never fetched; over SSH the path must exist on the machine running Pi.
Missing preview?
Give the preview time to decode. Save any draft text you want to keep, then run /img-preview-status from an empty editor. It reports whether the extension is enabled, how many images are listed, and the last decode result, including whether it used a fallback path. It does not include local paths or filenames.
The extension identifies image formats by file contents. It supports PNG, JPEG, static WebP, and the first frame of GIF files. SVG, HEIC, animated WebP, and unsupported or unreadable files are skipped. JPEG EXIF orientation is not applied.
How it renders
The preview is colored text. Each ▀ upper half block uses its foreground color for the top pixel and its background color for the bottom pixel. The renderer sets both colors with an SGR escape sequence when the color pair changes. A 90×50-pixel preview takes 90 columns and 25 rows. All you need is a terminal with SGR color, a font that includes ▀ (U+2580), and enough space.
| Color mode | What a preview looks like |
|---|---|
24-bit color (COLORTERM=truecolor, iTerm2, Kitty, WezTerm, Ghostty, VS Code, Windows Terminal, or PI_TRUE_COLOR=1) | colors close to the original |
256 colors (Apple Terminal, screen/tmux without a true-color hint, unrecognized terminals, or PI_TRUE_COLOR=0) | colors mapped to the xterm palette, which can make gradients look stepped |
No color (NO_COLOR or TERM=dumb) | previews disabled |
Colors and transparency
| Variable | Default | Values |
|---|---|---|
PI_IMG_PREVIEW_COLOR | auto | auto, truecolor, 256 |
PI_IMG_PREVIEW_BACKGROUND | #1e1e1e | #RRGGBB |
If auto-detection picks the wrong mode, set PI_IMG_PREVIEW_COLOR=truecolor or PI_IMG_PREVIEW_COLOR=256. Either setting takes precedence over Pi's PI_TRUE_COLOR. If transparent images look wrong, match the preview background to your terminal, for example PI_IMG_PREVIEW_BACKGROUND='#ffffff' for a white background. Setting NO_COLOR or TERM=dumb disables previews regardless of the selected color mode.
Limits and development
- Interactive TUI only. The extension checks the draft every 300 ms; decoding adds latency. It does not poll the clipboard or watch files. In print, JSON, or RPC mode, it does not poll the draft.
- Regular files up to 10 MiB and 16 million pixels. One Photon WASM worker at a time per session, with a 5-second decode deadline. Files are read only and changing files are discarded. These limits are safeguards, not a security sandbox.
- Eight decoded rasters and up to 32 failed decodes are cached separately by path and file metadata. Scanning is limited to 32 candidate paths and drafts of at most 65,536 UTF-16 code units.
npm run check
npm test
npm run demo
npm pack --dry-run --ignore-scripts
npm run demo creates synthetic fixtures in .demo/ and prints the widget using the same renderer; it does not run Pi. The source repository has the verification guide and the terminal acceptance checklist.
MIT. Image decoding uses Photon, which is Apache-2.0 licensed. Label layout uses Pi's own TUI width utilities.