Skip to content

FBnil/image2ascii

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

image2ascii.pl

Convert an image, using ImageMagick to an ANSI colour image, which can be printed on a terminal. It does this by printing Unicode Character 'LOWER HALF BLOCK' and grab 2 pixel rows to use as foreground and background color. With a little Perl to glue all together.

./image2ascii.pl <-i inputfile> [-o outputfile] [-r] [-c] [-z] [-v] [-w width]
 -i: inputfile (any non transparant image that convert can use)
 -w: Resize using width only (keeps aspect ratio). Use x16 for resized height
 -o: Optional outputfile
 -r: Use an RGB256 color palette. The default is TrueColor
 -c: Try to use less ANSI control characters resulting in a smaller file
 -z: Optionally gzip the outputfile.
 -x: Optional string to pass extra parameters to convert.
 -v: Verbose (use twice for more output)

A gzipped outputfile can be displayed using: zcat outfile.ascii.gz |bash -C

Dependencies

Uses "convert" from ImageMagick. Uses gzip (if -z is used). uses tr

Usage Example

# Dump the example rose image from ImageMagick:
convert rose: rose.png
# Display it in TrueColor ANSI at the original size:
./image2ascii.pl -i rose.png -w 100%
# If that did not display, use 256 colors instead and resize to 32 pixels wide:
reset; ./image2ascii.pl -i rose.png -w 32 -r

Visual Example

visual_example

In particular with flat looking images when viewing them with -r (256 color palette), you can dither them.

For example: ./image2ascii.pl -i rose.png -x '-ordered-dither checks,2' -r makes the colors more vivid. And for pictures of faces these seem to do pretty well: -x '-ordered-dither o4x4,8' or -x '-ordered-dither checks,8'

For all options, see the ImageMagick documentation:

Other similar projects

It's an online converter, but the resulting colors are sub-par.

Algorithms used from others

  • Uses the excelent color reduction algorithm from QIX

About

Convert an image, using ImageMagick to an ANSI colour image (Linux only)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages