Last active
December 18, 2015 01:19
-
-
Save aczid/5703046 to your computer and use it in GitHub Desktop.
Make quick & dirty ASCII art out of a hex string and TTF fonts - example at https://github.com/aczid/ru_crypto_engineering/blob/master/README.md#ascii-art
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageFont, ImageDraw | |
import sys | |
# Prettify ascii into a TTF rendered ascii art banner | |
if not len(sys.argv) > 1: | |
print "Supply string to render" | |
sys.exit() | |
if not len(sys.argv) > 2: | |
print "Supply size" | |
sys.exit() | |
if not len(sys.argv) > 3: | |
print "Supply input code" | |
sys.exit() | |
if not len(sys.argv) > 4: | |
print "Supply font" | |
sys.exit() | |
try: | |
image = Image.new("RGB", (140,30), (255,255,255)) | |
usr_font = ImageFont.truetype(sys.argv[4], int(sys.argv[2])) | |
d_usr = ImageDraw.Draw(image) | |
d_usr = d_usr.text((0,0), sys.argv[1], (0,0,0), font=usr_font) | |
data = list(image.getdata()) | |
image.save("test.png") | |
width,height = image.size | |
input_str = sys.argv[3] | |
input_index = 0 | |
print sys.argv[4] | |
for y in range(0, height): | |
for x in range(0, width): | |
if data[(y*width)+x] == (255,255,255): | |
sys.stdout.write(" ") | |
else: | |
if input_index < len(input_str): | |
sys.stdout.write(input_str[input_index]) | |
input_index += 1 | |
else: | |
sys.stdout.write("0") | |
sys.stdout.write("\n") | |
except (Exception): | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment