Skip to content
docsv0.3.0

ImageRenderer

Image placeholder renderer with optional Kitty/iTerm2 inline-image passthrough. The TUI analog of pi-tui's `Image` component. PHP does not have native Kitty graphics protocol bindings, so this renderer is intentionally conservative: when the terminal is known to support inline images (via `props['protocol']` = `'kitty'` or `'iterm2'`), it emits the raw base64 escape the caller supplied in `props['data']`; otherwise it renders a text placeholder describing the image (`[image: name.png · 800×600]`) so the layout still accounts for the image's cell footprint and the user knows an image lives there. The caller is responsible for: - Detecting terminal capabilities (Kitty vs iTerm2 vs none) and passing the right `protocol`/`data` props. - Pre-encoding the image data as base64. - Pre-computing the cell dimensions from the pixel dimensions and the terminal's cell aspect ratio. This keeps the renderer pure and free of native I/O — the same "node-in/frame-out" contract every other renderer in this namespace follows. Node props (all optional): - `data` string Base64-encoded image data, used only when `protocol` is set. - `mimeType` string Image MIME type (e.g. `'image/png'`). Default: `'image/png'`. - `protocol` string `'kitty'` | `'iterm2'` | `'none'`. Default: `'none'`. - `filename` string Shown in the placeholder. Default: ''. - `widthPx` int Image width in pixels (placeholder only). Default: 0. - `heightPx` int Image height in pixels (placeholder only). Default: 0. - `widthCells` int Image width in terminal cells (layout footprint). Default: derived. - `heightCells` int Image height in terminal cells (layout footprint). Default: 1. - `maxWidthCells` int Cap on width. Default: node width. - `maxHeightCells` int Cap on height. Default: node height. - `fallbackColor` string Theme role for the placeholder text. Default: 'muted'.

ImageRenderer::supports()

public function supports(Milpa\Live\ValueObjects\Tui\TuiNode $node): bool

True only for `image` nodes — dispatch is by declared node type, never by where the node came from.

Parameters

Parameters of supports()
NameTypeDescription
$nodeMilpa\Live\ValueObjects\Tui\TuiNode

ImageRenderer::render()

public function render(Milpa\Live\ValueObjects\Tui\TuiNode $node, Milpa\Live\ValueObjects\Tui\TuiRenderContext $context): Milpa\Live\ValueObjects\Tui\TuiFrame

Emits the inline-image escape sequence when the terminal supports it, and a labelled placeholder box when it does not.

Parameters

Parameters of render()
NameTypeDescription
$nodeMilpa\Live\ValueObjects\Tui\TuiNode
$contextMilpa\Live\ValueObjects\Tui\TuiRenderContext