Did #18
import os, sysfrom PIL import Imagedef imgtoascii(pathtoimg): charx = 2 chary = 5 rangepervalue = 3 asciiequivalent = ( "@", "#", "M", "B", "H", "E", "N", "R", "K", "W", "X", "D", "F", "P", "Q", "A", "S", "U", "Z", "b", "d", "e", "h", "x", "8", "&", "G", "*", "m", "O", "4", "a", "g", "n", "s", "6", "9", "o", "w", "z", "$", "C", "I", "u", "2", "3", "J", "c", "f", "r", "y", "%", "1", "v", "7", "l", "+", "i", "t", "[", "]", "{", "}", "?", "j", "|", "(", ")", "=", "~", "!", "-", "/", "", '"', "^", "_", "'", ";", ",", ":", "`", ".", " " ) # Check if pathtoimg is valid then convert to grayscale try: img = Image.open(pathtoimg).convert("LA") except IOError: print("Unable to open file") return False output = open(os.path.splitext(pathtoimg)[0]+".txt", "w") line = "" imgx, imgy = img.size # Loop through image and get each region to be converted to ASCII for y in range(0, imgy, chary): for x in range(0, imgx, charx): region = (x, y, x+charx, y+chary) grayscaleval = getgrayscalevalue(img.crop(region)) / rangepervalue grayscaleval = 0 if (grayscaleval == 0) else (grayscaleval - 1) line += asciiequivalent[grayscaleval] output.write(line + "\n") line = "" output.closedef getgrayscalevalue(region): total = 0 pixels = list(region.getdata()) for pixel in pixels: total += pixel[0] return(total/len(pixels))if __name__ == "__main__": for arg in sys.argv: imgtoascii(arg)