Got examples, now selects a random word if the user has a wordlist installed
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
all:
|
all:
|
||||||
rm -rf out||:
|
rm -rf out||:
|
||||||
mkdir out
|
mkdir out
|
||||||
python3 test.py
|
python3 generate.py
|
||||||
|
|
After Width: | Height: | Size: 228 KiB |
After Width: | Height: | Size: 224 KiB |
After Width: | Height: | Size: 256 KiB |
After Width: | Height: | Size: 235 KiB |
After Width: | Height: | Size: 264 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 297 KiB |
After Width: | Height: | Size: 305 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 292 KiB |
After Width: | Height: | Size: 275 KiB |
After Width: | Height: | Size: 294 KiB |
After Width: | Height: | Size: 398 KiB |
After Width: | Height: | Size: 312 KiB |
After Width: | Height: | Size: 198 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 192 KiB |
After Width: | Height: | Size: 335 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 574 KiB |
After Width: | Height: | Size: 294 KiB |
After Width: | Height: | Size: 257 KiB |
After Width: | Height: | Size: 206 KiB |
After Width: | Height: | Size: 232 KiB |
After Width: | Height: | Size: 203 KiB |
After Width: | Height: | Size: 208 KiB |
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 194 KiB |
21
generate.py
|
@ -1,5 +1,5 @@
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import subprocess
|
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":
|
if result == "tmp":
|
||||||
|
@ -8,14 +8,27 @@ def getFontName(font, extra = False):
|
||||||
result += "-" + font.split("/")[-1]
|
result += "-" + font.split("/")[-1]
|
||||||
return result
|
return result
|
||||||
i=0
|
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")
|
null = open("/dev/null", "w")
|
||||||
print(" ".join(["find", "/home/niles/Documents/fonts", "-type", "f", "-iregex", ".*\\.ttf|.*\\.otf"]))
|
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
|
||||||
print("Generating " + str(i) + getFontName(font, True))
|
idx = str(i).zfill(len(str(len(fonts))))
|
||||||
|
print("Generating " + idx + getFontName(font, True))
|
||||||
try:
|
try:
|
||||||
|
if os.path.exists(wordlist):
|
||||||
|
word = ""
|
||||||
|
while len(word) < 8:
|
||||||
|
wllen = subprocess.check_output(["wc", "-l", wordlist]).decode("utf-8").strip().split()[0]
|
||||||
|
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:
|
||||||
|
continue
|
||||||
|
word = word + " " + newword
|
||||||
|
print(word)
|
||||||
txt = Image.new('RGBA', (2000, 2400), (211,141,95, 255))
|
txt = Image.new('RGBA', (2000, 2400), (211,141,95, 255))
|
||||||
#txt.putpixel((x, y), (255, 127, 42, 255))
|
#txt.putpixel((x, y), (255, 127, 42, 255))
|
||||||
d = ImageDraw.Draw(txt)
|
d = ImageDraw.Draw(txt)
|
||||||
|
@ -29,14 +42,14 @@ for font in fonts:
|
||||||
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))
|
||||||
fnt = ImageFont.truetype(font, 200)
|
fnt = ImageFont.truetype(font, 200)
|
||||||
d.text((100,1200), "The brown fox jumps over the lazy red dog or something", font=fnt, fill=(0,0,0,255))
|
d.text((100,1200), word, font=fnt, fill=(0,0,0,255))
|
||||||
fnt = ImageFont.truetype(font, 180)
|
fnt = ImageFont.truetype(font, 180)
|
||||||
d.text((100,1700), "abcdefghijklm", font=fnt, fill=(0,0,0,255))
|
d.text((100,1700), "abcdefghijklm", font=fnt, fill=(0,0,0,255))
|
||||||
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)
|
out = txt#Image.alpha_composite(base, txt)
|
||||||
out.save("out/" + str(i) + "-" + getFontName(font, True) + ".png")
|
out.save("out/" + idx + "-" + getFontName(font, True) + ".png")
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
|