NAME
Text::ANSI::Image - images as lines of text for the terminal
SYNOPSIS
use Text::ANSI::Image;
my $img = Text::ANSI::Image->new or exit; # no method for the terminal
print "$_\n" for $img->rows('logo.png', width => 40);
$img->flush;
VERSION
Version 0.01
DESCRIPTION

This module draws an image in a terminal as lines of text. The lines
can be laid out, folded around, paged and scrolled like any other
text: put in columns by ansicolumn(1), shown by
less, and they stay with the text around them.
How the lines are made is the method. Each method is a module
Text::ANSI::Image::NAME. The one of this distribution is:
-
kittyThe Unicode placeholders of the kitty graphics protocol. Each cell of the image is the character U+10EEEE, with its row and column as combining characters and the id of the image as the foreground color. The image itself is sent to the terminal once, by flush, and the terminal draws it in the cells, in its full resolution. kitty, Ghostty and iTerm2 3.7.3 or later support it.
PNG, JPEG and GIF files are shown. The type is detected from the
content, not the name of the file. The kitty method sends PNG; a
JPEG or a GIF is converted to PNG by sips (macOS) or ImageMagick,
and is not shown without them. A PNG much larger than the room is
reduced by the same tools to send less data, or sent as it is without
them.
METHODS
-
new(OPTIONS)
Returns an object of a method. The options are:
-
method => NAME
The method:
kitty, orauto(the default), the first method in@Text::ANSI::Image::METHODSwhich the terminal supports. Withauto, new returnsundefwhen the terminal supports none. An unknown name dies. -
term => COLSxROWS[:WxH]
The size of the terminal, in columns and rows, and the size of a cell in pixels. By default it is read from
/dev/tty. A cell of 8x17 pixels is taken when its size is not known. -
tty => FILE
Where the data of the images is sent by flush (default:
/dev/tty). -
width => N, rows => N
The most columns and rows that an image may take (default: the terminal width, and its height but four lines).
-
types => [ TYPE, ... ]
The types of images shown:
png,jpegandgif(default: all).
-
-
rows(FILE, OPTIONS)
Returns the rows of the image of FILE, as lines without newlines, or an empty list when it is not shown: the file is not found, not an image, of a type not in types, or cannot be converted. width, rows and types may be given for this call. An image is as large as its pixels, and not larger than the room.
-
flush
Sends to the terminal what the rows given so far need: the images for
kitty. Call it before the rows are shown, or soon after. -
method
The name of the method of the object.
-
supported
Whether the terminal supports the method, by the environment. It is a class method:
Text::ANSI::Image::kitty->supported. -
terminal
Columns, rows and the size of a cell in pixels of the terminal. As a class method, it takes term as the argument:
Text::ANSI::Image->terminalreads the size of/dev/tty. -
info(FILE)
Width, height and type of an image file, or an empty list. It is a class method too.
-
cells(W, H, OPTIONS)
The columns and rows that an image of W x H pixels takes.
METHOD MODULES
A method is a module Text::ANSI::Image::NAME, a subclass of
Text::ANSI::Image, which has:
-
render(FILE, W, H, TYPE, COLS, ROWS)
The rows of the image in COLS x ROWS cells. Required.
-
supported
Whether the terminal supports it (default: no).
-
max_cells
The most columns and rows it can draw (default: 0, no limit).
-
flush
What is sent to the terminal (default: nothing).
png is there for a method which needs a PNG of the image.
SEE ALSO
Terminal graphics protocol, Unicode placeholders
App::mdee, which shows the images of Markdown files with it.
App::ansicolumn, Text::ANSI::Fold
AUTHOR
Kazumasa Utashiro
LICENSE
Copyright © 2026 Kazumasa Utashiro.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.