Image rendering for terminal emulators.
Supports multiple protocols:
- Kitty Graphics Protocol
- iTerm2 Inline Images
- Sixel (via img2sixel)
- ASCII fallback
Usage
# Render an image file
Alaja.ImageRenderer.render_file("image.png")
# Render pixel data directly
pixels = for y <- 0..99, do: for x <- 0..99, do: {x * 2, y * 2, 128}
Alaja.ImageRenderer.render(pixels, width: 100, height: 100)
# Detect protocol
protocol = Alaja.ImageRenderer.detect_protocol()
Summary
Functions
Detects the best protocol for the current terminal.
Generates a PNG binary from pixel data.
Generates a PNG binary from RGBA pixel data (with alpha channel for transparency).
Renders pixel data to the terminal.
Renders an image as colored or monochrome ASCII art.
Renders an image file to the terminal.
Functions
@spec detect_protocol() :: :kitty | :iterm2 | :sixel | :ascii
Detects the best protocol for the current terminal.
@spec generate_png( [[{non_neg_integer(), non_neg_integer(), non_neg_integer()}]], pos_integer(), pos_integer() ) :: binary()
Generates a PNG binary from pixel data.
Parameters
pixels- List of rows, each row a list of{r, g, b}tupleswidth- Image width in pixelsheight- Image height in pixels
@spec generate_png_rgba( [ [ {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()} ] ], pos_integer(), pos_integer() ) :: binary()
Generates a PNG binary from RGBA pixel data (with alpha channel for transparency).
Parameters
pixels- List of rows, each row a list of{r, g, b, a}tupleswidth- Image width in pixelsheight- Image height in pixels
@spec render( [[{non_neg_integer(), non_neg_integer(), non_neg_integer()}]], keyword() ) :: :ok | :unsupported
Renders pixel data to the terminal.
Parameters
pixels- List of rows, each row is a list of{r, g, b}tuples
Renders an image as colored or monochrome ASCII art.
Only PNG is supported natively (pure Elixir). For other formats,
ImageMagick (convert) is required as a fallback.
Options
:width— target width in characters (default: 40):height— target height in characters (default: auto from aspect ratio):ascii_style— character set preset (:blocks,:detailed,:simple,:braille):ascii_chars— custom character string (overrides:ascii_style):ascii_color— whether to colorize output (default: true):ascii_saturation— color saturation 0.0-1.0 (default: 1.0)
Renders an image file to the terminal.
Options
:width- Target width in cells:height- Target height in cells:protocol- Force a specific protocol (:kitty,:iterm2,:sixel,:ascii)