Do you remeber the "old" internet? before webbrowsers, when everything had a strong unix flavour? Back then there was something called "ascii art" that is, use the ascii letters to create an image. Here is a program that takes an image (640x384) and converts it to ascii strings. I wanted to create this image for a
t-shirt
You would need to copy the "courier new" font from your font directory to the same directory as the script, and also add an image that should be converted:
-
import Image, ImageDraw
-
import ImageFont
-
import math
-
-
# funny useless program
-
-
lu = []
-
for i in range(125-32):
-
lu.append(chr(i+33))
-
i2 = Image.new("RGBA",(64,64))
-
ii = Image.open("mona.png") # change this to your own picture, but it needs to be 640x384!
-
im = Image.new("RGBA",(64,64))
-
d = ImageDraw.Draw(im)
-
f = ImageFont.truetype("courbi.ttf",13)
-
-
str=""
-
for v in range(24):
-
print v
-
for k in range(80):
-
chr = ""
-
maxdiff = 0xffffff
-
for e in lu:
-
d.rectangle([0,0,64,64], fill=0)
-
d.text((0,0),e,font=f,fill=0xffffff)
-
diff = 0
-
r0 = 0
-
g0 = 0
-
b0 = 0
-
for a in range(16):
-
for b in range(8):
-
c = im.getpixel((b,a))[0]
-
c0 = (ii.getpixel((b+(k*8),a+(v*16)))[0] + ii.getpixel((b+(k*8),a+(v*16)))[1] + ii.getpixel((b+(k*8),a+(v*16)))[2])/3.0
-
r0+= ii.getpixel((b+(k*8),a+(v*16)))[0]
-
g0+= ii.getpixel((b+(k*8),a+(v*16)))[1]
-
b0+= ii.getpixel((b+(k*8),a+(v*16)))[2]
-
-
diff+=abs(c-c0)
-
if(diff < maxdiff):
-
maxdiff = diff
-
chr = e
-
-
r0*=1.0
-
g0*=1.0
-
b0*=1.0
-
r0/=(16.0*8.0)
-
g0/=(16.0*8.0)
-
b0/=(16.0*8.0)
-
ir0 = int(r0)
-
ig0 = int(g0)
-
ib0 = int(b0)
-
-
r1 = hex(ir0)
-
r1 = r1[2:len(r1)]
-
g1 = hex(ig0)
-
g1 = g1[2:len(g1)]
-
b1 = hex(ib0)
-
b1 = b1[2:len(g1)]
-
-
if(chr == " "):
-
chr=" "
-
-
str+="<td width=\"8px\"><font size=\"1px\" color=\"#"+r1+g1+b1+"\">"+chr+"</font></td>"
-
str="<tr>"+str+"</tr>"
-
-
str= "<html><body bgcolor=\"#000000\"><table width=\"640px\" height=\"386px\">"+str+"</table></body></html>"
-
f = open("mona.txt","w")
-
f.write(str)
-
f.close()
-
This program output it as a .html file, but it should easy to modify so it will output txt instead.
-kudos