Author image Kevin Ryde
and 1 contributors


Image::Base::Text -- draw in a plain text file or grid


 use Image::Base::Text;
 my $image = Image::Base::Text->new (-width  => 70,
                                     -height => 20);
 $image->rectangle (5,5, 65,15, '*');
 $image->save ('/some/filename.txt');


Image::Base::Text is a subclass of Image::Base,



Image::Base::Text extends Image::Base to create or update text files treated as grids of characters, or just to create a grid of characters in memory.

Colours for drawing can be a single character to set in the image, or there's an experimental -colour_to_character attribute to map names to characters. Currently black, #000000, #000000000000 and clear all become spaces and anything else becomes a "*". Perhaps that will change.

Perl wide characters can be used, in new enough Perl, though currently there's nothing to set input or output encoding for file read/write (making it fairly useless, unless perhaps you've got global PerlIO layers setup).


See "FUNCTIONS" in Image::Base for the behaviour common to all Image-Base classes.

$image = Image::Base::Text->new (key=>value,...)

Create and return an image object. A image can be started with -width and -height,

    $image = Image::Base::Text->new (-width  => 70,
                                     -height => 20);

Or an existing file can be read,

    $image = Image::Base::Text->new (-file => '/my/filename.txt');
$new_image = $image->new (key=>value,...)

Create and return a cloned copy of $image. The optional parameters are applied to the new image as per set.

$image->load ()
$image->load ($filename)

Read a text file into $image, either from the current -file option, or set that option to $filename and read from there.

Tab characters in the file are expanded to spaces per Text::Tabs. Its $Text::Tabs::tabstop controls the width of each tab.

-height is set to the number of lines in the file, possibly zero. -width is set to the widest line in the file and other lines are padded with spaces to that width as necessary.

$image->save ()
$image->save ($filename)

Save the image to a text file, either the current -file option, or set that option to $filename and save to there.

Trailing spaces are included in the output so that the width is represented in the file, and to keep it a rectangular grid. Tabs are not used in the output.


-width (integer)
-height (integer)

Setting these resizes an image, either truncating or extending. When extending the new area is initialized to space characters.


Image::Base, Text::Tabs, Image::Xpm



Image-Base-Other is Copyright 2010, 2011, 2012 Kevin Ryde

Image-Base-Other is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Image-Base-Other is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Image-Base-Other. If not, see <>.