ratatui-image
Showcase:

Image widgets with multiple graphics protocol backends for Ratatui
⚠️ THIS CRATE IS EXPERIMENTAL, AND THE TERMWIZ RATATUI BACKEND DOES NOT WORK
Render images with graphics protocols in the terminal with Ratatui.
Quick start
use ;
use ;
Graphics protocols in terminals
Different terminals support different graphics protocols such as sixels, kitty-graphics-protocol, or iTerm2-graphics-protocol. If no such protocol is supported, it is still possible to render images with unicode "halfblocks" that have fore- and background color.
The [picker::Picker] helper is there to do all this graphics-protocol guessing, and also to map character-cell-size to pixel size so that we can e.g. "fit" an image inside a desired columns+rows bound etc.
Widget choice
The [ResizeImage] widget adapts to its render area, is more robust against overdraw bugs and artifacts, and plays nicer with some of the graphics protocols. However, frequent render area resizes might affect performance.
The [FixedImage] widgets does not adapt to rendering area (except not drawing at all if space is insufficient), is more bug prone (overdrawing or artifacts), and is not aligned with some of the protocols. Its only upside is that it is stateless (in terms of ratatui), and thus is not performance-impacted by render area resizes.
Examples
See the [crate::picker::Picker] helper and examples/demo.
The lib also includes a binary that renders an image file.
Features
sixel(default) compiles with libsixel.rustix(default) enables much better guessing of graphics protocols withrustix::termios::tcgetattr.crosstermortermionshould match your ratatui backend.termwizis available, but not working correctly with ratatu-image.serdefor#[derive]s on [picker::ProtocolType] for convenience, because it might be useful to save it in some user configuration.
Current version: 0.3.4
Sixel compatibility and QA:
| Terminal | Fixed | Resize | Notes |
|---|---|---|---|
| Xterm | ✔️ | ✔️ | |
| Foot | ✔️ | ✔️ | |
| kitty | ✔️ | ✔️ | |
| Alacritty | ✔️ | ❌ | with sixel patch, but never clears graphics. |
| iTerm2 | ❌ | ❌ | Unimplemented, has a protocolo similar to sixel |
| konsole | ❌ | ❌ | Does not clear graphics unless cells have a background style |
| Contour | ❌ | ❌ | Text over graphics |
| Wezterm | ❌ | ❌ | Buggy |
| ctx | ❌ | ❌ | Buggy |
| Blackbox | ❔ | ❔ | Untested |
Latest Xterm testing screenshot:

Halfblocks should work in all terminals.
Comparison:
- viuer Renders graphics in different terminals/protocols, but "dumps" the image, making it difficult to work for TUI programs. The terminal protocol guessing code has been adapted to rustix, thus the author of viuer is included in the copyright notice.
- yazi Not a library but a terminal file manager that implementes many graphics protocols and lets you preview images in the filesystem.
License: MIT