Skip to content

Instantly share code, notes, and snippets.

@winks
Created June 17, 2013 21:46
Show Gist options
  • Save winks/5800768 to your computer and use it in GitHub Desktop.
Save winks/5800768 to your computer and use it in GitHub Desktop.
import Image, ImageFont, ImageDraw, sys
IMG_SIZE = (40, 16)
FONT_SIZE = 12
FONT_OFFSET= (2,2)
C_BLACK = (0, 0, 0)
C_WHITE = (255, 255, 255)
STRING = "fnord"
if len(sys.argv) > 1:
STRING = sys.argv[1]
image = Image.new("RGBA", IMG_SIZE, C_BLACK)
draw = ImageDraw.Draw(image)
font = ImageFont.load_default()
draw.text(FONT_OFFSET, STRING, font=font, fill=C_WHITE)
#image.save("out.png")
imgmap = []
for pixel in image.getdata():
r, g, b, a = pixel
if r == 255:
imgmap.append(1)
else:
imgmap.append(0)
print imgmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment