Convert images to text (ASCII art)
Recently, whilst messing with sprites and the Grrr framework, I got thinking about better graphics for games.
As PowerShell is very slow at doing console atomic write operations, a game should really have fewer, larger sprites. I then thought about ASCII art, and wouldn’t it be great if PowerShell could convert existing images (jpg, png) and produce lines of text for use with Grrr’s create-image function.
So my morning’s work is a PowerShell script that does just that.
You can download it here: convert-image2text.ps1 (as a text file)
(If you’re reading this from the RSS feed, the link may be broken – open the blog page if so)
Unfortunately, it’s only monochrome. I had a lot of trouble getting a reasonable conversion of RGB or HSV to the console’s limited colour palette and character range, so in the end, I removed it.
The script uses System.Drawing and demonstrates one (a good?) way of adding an assembly to PowerShell.
[ -maxwidth nchars ] [-palette ascii | shade | bw ]
Here’s an example using the default -palette ascii option:
Here’s the same with the -palette shade option:
Both are from this source image (click to see full size):