Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Convert an Image File to ASCII Art Using PowerShell

22 Sep 2009   #1

Windows 7 Professional, Windows XP
Convert an Image File to ASCII Art Using PowerShell

# Copyright 2006 Adrian Milliner (ps1 at soapyfrog dot com)
# This work is licenced under the Creative Commons 
# Attribution-NonCommercial-ShareAlike 2.5 License. 
# To view a copy of this licence, visit 
# or send a letter to 
# Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
# This script loads the specified image and outputs an ascii version to the
# pipe, line by line.
  [string]$path = $(throw "Supply an image path"),
  [int]$maxwidth,            # default is width of console
  [string]$palette="ascii",  # choose a palette, "ascii" or "shade"
  [float]$ratio = 1.5        # 1.5 means char height is 1.5 x width
# here we go
$palettes = @{
  "ascii" = " .,:;=|iI+hHOE#`$"
  "shade" = " " + [char]0x2591 + [char]0x2592 + [char]0x2593 + [char]0x2588
  "bw"    = " " + [char]0x2588
$c = $palettes[$palette]
if (-not $c) {
  write-warning "palette should be one of:  $($palettes.keys.GetEnumerator())"
  write-warning "defaulting to ascii"
  $c = $palettes.ascii
[char[]]$charpalette = $c.ToCharArray()
# we need the drawing assembly
$dllpath=(get-command "system.drawing.dll").definition
[Reflection.Assembly]::LoadFrom($dllpath) | out-null
# load the image
$image = [Drawing.Image]::FromFile($path)
if ($maxwidth -le 0) { [int]$maxwidth = $host.ui.rawui.WindowSize.Width - 1}
[int]$imgwidth = $image.Width
[int]$maxheight = $image.Height / ($imgwidth / $maxwidth) / $ratio
$bitmap = new-object Drawing.Bitmap ($image,$maxwidth,$maxheight)
[int]$bwidth = $bitmap.Width; [int]$bheight = $bitmap.Height
# draw it!
$cplen = $charpalette.count
for ([int]$y=0; $y -lt $bheight; $y++) {
  $line = ""
  for ([int]$x=0; $x -lt $bwidth; $x++) {
    $colour = $bitmap.GetPixel($x,$y)
    $bright = $colour.GetBrightness()
    [int]$offset = [Math]::Floor($bright*$cplen)
    $ch = $charpalette[$offset]
    if (-not $ch) { $ch = $charpalette[-1] } #overflow
    $line += $ch

./convert-image2text.ps1 imagefile [ -maxwidth nchars ] [-palette ascii | shade | bw ]
Full article > Convert images to text (ASCII art)

My System SpecsSystem Spec

Thread Tools

Similar help and support threads
Thread Forum
Need to convert wma to mp3 file
Trying to upload my music to Google Music through the Music Manager software, but it refuses to upload wma (protected) audio files. I thought fre:ac Audio Converter would do the trick, but it couldn't. Does anyone know of a good freeware that can do this? :p
Music, Pictures & Video
How to convert a windows WIM file to a ISO file
I am trying to find a way to take a WIM file from WDS, and convert it to an ISO image, so that I can use the ISO to install into VMware machines. I've read the many posts on how to convert a discover.wim to an ISO, but this doesn't work for what I'm trying to do. Any suggestions on how to get...
General Discussion
file convert .ts to another
i have a .ts file that is 350 mb in size i want to convert it to another file with the exact same quality i do not mind what extension whatever is the best
Music, Pictures & Video
How to convert a bat file
Hi I have a bat file that i want to convert it into an exe file with an icon. I tried converting it first time using a program,but norton internet sec says that it's a virus. So how do I convert the file in cmd? Thanks.
General Discussion
trying to restore acronis image fails, convert to vhd and boot?
for backups of my main OS (in my signature) I have acronis TIH create a single image full backup daily to a different drive. Weekly a single image backup is created and saved on a different drive. Because my SSDs are in RAID0, every few weeks I make a system image backup using Acronis (outside of...
How convert exe to zip file?
Does anyone know of any software or method to take a self-extracting exe file and (de)convert it to a zip file? I've just learned of a method to create a portable app for my thumb drive; but it presupposes a zip file as input. I have a number of paid-for applications that I would like to...

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 08:50.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App