Cleaned up code, removed debug, added comments
This commit is contained in:
parent
719ca3d7e2
commit
2f387c0444
13
generate.py
13
generate.py
|
@ -2,8 +2,6 @@ from PIL import Image, ImageDraw, ImageFont
|
||||||
import subprocess, os, random
|
import subprocess, os, random
|
||||||
def getFontName(font, extra = False):
|
def getFontName(font, extra = False):
|
||||||
result = font.split("/")[-2]
|
result = font.split("/")[-2]
|
||||||
if result == "tmp":
|
|
||||||
return font.split("/")[-1]
|
|
||||||
if extra:
|
if extra:
|
||||||
result += "-" + font.split("/")[-1]
|
result += "-" + font.split("/")[-1]
|
||||||
return result
|
return result
|
||||||
|
@ -11,18 +9,18 @@ i=0
|
||||||
word = "The brown fox jumps over the lazy red dog or something"
|
word = "The brown fox jumps over the lazy red dog or something"
|
||||||
wordlist = "/usr/share/dict/american-english"
|
wordlist = "/usr/share/dict/american-english"
|
||||||
null = open("/dev/null", "w")
|
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]
|
fonts = subprocess.check_output(["find", "/home/niles/Documents/fonts", "-type", "f", "-iregex", ".*\\.\(ttf\|otf\)"]).decode("utf-8").split("\n")[:-1]
|
||||||
i = 0
|
i = 0
|
||||||
for font in fonts:
|
for font in fonts:
|
||||||
i+=1
|
i+=1
|
||||||
idx = str(i).zfill(len(str(len(fonts))))
|
idx = str(i).zfill(len(str(len(fonts))))
|
||||||
print("Generating " + idx + getFontName(font, True))
|
print("Generating " + idx + " " + getFontName(font, True))
|
||||||
try:
|
try:
|
||||||
if os.path.exists(wordlist):
|
if os.path.exists(wordlist):
|
||||||
word = ""
|
word = ""
|
||||||
while len(word) < 8:
|
while len(word) < 8:
|
||||||
wllen = subprocess.check_output(["wc", "-l", wordlist]).decode("utf-8").strip().split()[0]
|
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 = 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:]
|
newword = newword[0].upper() + newword[1:]
|
||||||
if '\'' in newword:
|
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))
|
d.text((100,110), getFontName(font, True), font=fnt, fill=(0,0,0,255))
|
||||||
fnt = ImageFont.truetype(font, 300)
|
fnt = ImageFont.truetype(font, 300)
|
||||||
d.text((50,450), "Aa Ee Rr", font=fnt, fill=(0,0,0,255))
|
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))
|
d.text((50,750), "Aa Ee Rr", font=fnt, fill=(0,0,0,255))
|
||||||
fnt = ImageFont.truetype(font, 800)
|
fnt = ImageFont.truetype(font, 800)
|
||||||
d.text((1500,300), "a", font=fnt, fill=(255,255,255,255))
|
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))
|
d.text((100,1900), "nopqrstuvwxyz", font=fnt, fill=(0,0,0,255))
|
||||||
fnt = ImageFont.truetype(font, 250)
|
fnt = ImageFont.truetype(font, 250)
|
||||||
d.text((450,2100), "0123456789", font=fnt, fill=(255,255,255,255))
|
d.text((450,2100), "0123456789", font=fnt, fill=(255,255,255,255))
|
||||||
out = txt#Image.alpha_composite(base, txt)
|
txt.save("out/" + idx + "-" + getFontName(font, True) + ".png")
|
||||||
out.save("out/" + idx + "-" + getFontName(font, True) + ".png")
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
pass
|
||||||
print(traceback.format_exc())
|
|
||||||
|
|
Loading…
Reference in New Issue