Cleaned up code, removed debug, added comments

This commit is contained in:
Niles Rogoff 2016-10-24 14:37:10 -04:00
parent 719ca3d7e2
commit 2f387c0444
1 changed files with 4 additions and 9 deletions

View File

@ -2,8 +2,6 @@ from PIL import Image, ImageDraw, ImageFont
import subprocess, os, random
def getFontName(font, extra = False):
result = font.split("/")[-2]
if result == "tmp":
return font.split("/")[-1]
if extra:
result += "-" + font.split("/")[-1]
return result
@ -11,18 +9,18 @@ i=0
word = "The brown fox jumps over the lazy red dog or something"
wordlist = "/usr/share/dict/american-english"
null = open("/dev/null", "w")
print(" ".join(["find", "/home/niles/Documents/fonts", "-type", "f", "-iregex", ".*\\.ttf|.*\\.otf"]))
fonts = subprocess.check_output(["find", "/home/niles/Documents/fonts", "-type", "f", "-iregex", ".*\\.\(ttf\|otf\)"]).decode("utf-8").split("\n")[:-1]
i = 0
for font in fonts:
i+=1
idx = str(i).zfill(len(str(len(fonts))))
print("Generating " + idx + getFontName(font, True))
print("Generating " + idx + " " + getFontName(font, True))
try:
if os.path.exists(wordlist):
word = ""
while len(word) < 8:
wllen = subprocess.check_output(["wc", "-l", wordlist]).decode("utf-8").strip().split()[0]
# Unsafe
newword = subprocess.check_output(["bash", "-c", "head -n " + str(random.randint(0,int(wllen))) + " " + wordlist + "|tail -n 1"]).decode("utf-8").strip()
newword = newword[0].upper() + newword[1:]
if '\'' in newword:
@ -37,7 +35,6 @@ for font in fonts:
d.text((100,110), getFontName(font, True), font=fnt, fill=(0,0,0,255))
fnt = ImageFont.truetype(font, 300)
d.text((50,450), "Aa Ee Rr", font=fnt, fill=(0,0,0,255))
fnt = ImageFont.truetype(font, 300)
d.text((50,750), "Aa Ee Rr", font=fnt, fill=(0,0,0,255))
fnt = ImageFont.truetype(font, 800)
d.text((1500,300), "a", font=fnt, fill=(255,255,255,255))
@ -48,8 +45,6 @@ for font in fonts:
d.text((100,1900), "nopqrstuvwxyz", font=fnt, fill=(0,0,0,255))
fnt = ImageFont.truetype(font, 250)
d.text((450,2100), "0123456789", font=fnt, fill=(255,255,255,255))
out = txt#Image.alpha_composite(base, txt)
out.save("out/" + idx + "-" + getFontName(font, True) + ".png")
txt.save("out/" + idx + "-" + getFontName(font, True) + ".png")
except:
import traceback
print(traceback.format_exc())
pass