: Is there a command-line program that can output ascii art as an image? Is there a command-line program (for Linux) that can convert an image to ascii art and then save that output as an image
Is there a command-line program (for Linux) that can convert an image to ascii art and then save that output as an image e.g. jpg or png?
To illustrate what I'm in need of, I want to convert the image below into ascii art
The output that I desire from a program should be similar to this one, which was created by taking a screenshot of the output of an image-to-ascii converter (the output was pure text)
I'm aware that GIMP has the ability to save an image as ascii art and aview can also convert an image to ascii. However, the former cannot be done via the command line and the latter only lets you view the output, not save it (I don't want to resort to taking a screenshot of the output).
I'm also aware that libcaca can save its output to an image, but it only outputs colourful ascii, like below.
Made by converting the source image to greyscale and then with the following command:
img2txt -W 70 -f tga input.jpg > output.tga
The reason for wanting a command-line program is to batch process a folder full of images.
More posts by @Dunderdale640
6 Comments
Sorted by latest first Latest Oldest Best
I use jp2a for ascii art. Straightforward to use from command line:
jp2a --width=76 file.jpg
And can test results online at asciiconvert.com.
As long as I am aware that program doesn't have a command line interface, but does convert images to text and then to images. Source is available, so you can use it to write your own tool.
You are right, aalib doesn't output images, but it does output text. As well as many other programs that work on command line.
If you're using Linux, there is a command line program called asciitopgm that will convert ascii text to a bitmap. It's part of the netpbm package.
So you can use a combination of tools:
aalib to draw an image using text
asciitopgm to create a pgm bitmap with the text file.
(optional) Use convert (From Imagemagick package) to convert the pgm to any other raster format you want.
I think you can do what you wanted to this way.
You seem to be Using Linux, and already know libcaca. There is another lib that does exactly what you say (Image to Ascii on command line): Aalib.
There are many programs do this. This one works both on Linux and windows. Doesn't use external libraries, full source code available, etc...
You can use this python code I created to create ascii art from still images and videos:
gist.github.com/lindylex/9374326
Example output
Original
ASCII art output (python ascii_movie_image_ver_1.py cat.jpg 4 10)
In case you seem to be running Linux you may stitch the applications easily together to get the desired result. This can then also be incorporated in your batch processing script.
The example below makes use of jp2a, a powerfull JPG to ASCII-art converter with many options to achieve desired results (consult the manpage). We then further process the resulting ASCII text file to an image using convert from the ImageMagick suite. Again there are many options to fine tune the result. Both applications are likely to be available from your distribution's repositories.
Below sample script will produce an ASCII-art image (format depending on the extension we give, .jpg is for JPEG) from an input JPEG-image. The source is rendered to 160 character width at 6 pt. This will then just fit on the default page size as pre-defined from convert.
#! /bin/bash #Usage ./j2asc infile.jpg outfile.jpg
echo "converting to "
jp2a --width=160 -i --output=tmp.txt
convert -font Courier -pointsize 6 tmp.txt
In Node.js Knockout 2012, there was a winning submission that took a webcam video feed and spit out an "ascii feed":
Asciigram
Asciigram is a "productivity tool" that allows you to creates ASCII videos and images using your webcam. You can also create ASCII images dragging images onto the page.[Link]
It's not exactly command line, but maybe you can retrofit it for your needs. The library they use to convert the image to ascii is called Jscii.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.