This program takes a word list & an input image, and produces an ascii art version of that image using only words from the list. It behaves similarly to libaa if you pass in a 'word list' consisting of printable ascii (although it adds a space before each word).
How this is actually implemented is a little more interesting. I render each word of text twice (once with regular color and once inverted), and I use those word masks to mask out pieces of the source image, then counting the average value of the remaining pixels. I score words based on how close they get to covering all the filled-in pixels in the section & not covering any of the non-filled-in ones (or getting approximately the same shading ratio in the normal case).
Please note, if you're planning to run this, that it expects a newish version of pillow, built with the freetype extension. The PIL/Pillow that ships with debian & ubuntu won't work, and to install from pip on those platforms you will need the dev packages for libfreetype & libjpeg.
This program takes a word list & an input image, and produces an ascii art version of that image using only words from the list. It behaves similarly to libaa if you pass in a 'word list' consisting of printable ascii (although it adds a space before each word).
How this is actually implemented is a little more interesting. I render each word of text twice (once with regular color and once inverted), and I use those word masks to mask out pieces of the source image, then counting the average value of the remaining pixels. I score words based on how close they get to covering all the filled-in pixels in the section & not covering any of the non-filled-in ones (or getting approximately the same shading ratio in the normal case).
Given this source image and the first 100 lines of this word list, I produced this output, and the inverted image produces this.
Source: https://github.com/enkiv2/misc/blob/master/napogenmo2017/asciiImage.py
Please note, if you're planning to run this, that it expects a newish version of pillow, built with the freetype extension. The PIL/Pillow that ships with debian & ubuntu won't work, and to install from pip on those platforms you will need the dev packages for libfreetype & libjpeg.