Using NodeJS to asciify images
In this post, I'll describe how to use image-to-ascii
for converting images into ASCII art. This is built by me and it is open-sourced on GitHub.
It's super easy to use. Let's take a look.
Prerequisites
You have to install GraphicsMagick before using this package:
$ sudo apt-get install graphicsmagick # Ubuntu
$ brew install graphicsmagick # Mac OS X
Usage
After the prerequisites are installed, you can install the module: npm install image-to-ascii
. Then you can start ASCIIfying images.
Let's use this Octocat in our tests. The url of the image is https://octodex.github.com/images/saint-nicktocat.jpg
.
So, to convert this image into ASCII art, you'll have to do the following below:
// Load the library
var img2ascii = require("image-to-ascii");
// Convert an octocat into ascii :)
img2ascii("https://octodex.github.com/images/saint-nicktocat.jpg", function (err, result) {
console.log(result);
})
The result is:
This is the default behavior. We can modify it using an object instead of a string.
Don't forget to browse the code and documentation on GitHub... and ASCIIfy the world!
This is great in presenting images, obviously the higher the resolution of the image the longer the time it will take to give the result of the ascii image.
Thanks! Yes, it depends on how big the image is and how big the image result should be. By default, the result will be the max-height/max-width of the terminal (keeping the aspect ratio).
There is an example how to ASCIIfy the webcam video in real time: https://github.com/IonicaBi… :-)