lobotmized goober and cleared out junk
This commit is contained in:
parent
b860d0e271
commit
8021d17d27
14 changed files with 19 additions and 1488 deletions
|
@ -12,10 +12,6 @@ generated_sentences = set()
|
|||
|
||||
def load_font(size):
|
||||
return ImageFont.truetype("assets/fonts/Impact.ttf", size=size)
|
||||
|
||||
def load_tnr(size):
|
||||
return ImageFont.truetype("assets/fonts/TNR.ttf", size=size)
|
||||
|
||||
def draw_text_with_outline(draw, text, x, y, font):
|
||||
outline_offsets = [(-2, -2), (-2, 2), (2, -2), (2, 2), (0, -2), (0, 2), (-2, 0), (2, 0)]
|
||||
for ox, oy in outline_offsets:
|
||||
|
@ -115,63 +111,3 @@ async def gen_meme(input_image_path, sentence_size=5, max_attempts=10, custom_te
|
|||
draw_text_with_outline(draw, truncated, (width - text_width) / 2, 0, font)
|
||||
img.save(input_image_path)
|
||||
return input_image_path
|
||||
|
||||
async def gen_demotivator(input_image_path, max_attempts=5):
|
||||
markov_model = load_markov_model()
|
||||
if not markov_model or not os.path.isfile(input_image_path):
|
||||
return None
|
||||
|
||||
attempt = 0
|
||||
while attempt < max_attempts:
|
||||
with Image.open(input_image_path).convert("RGB") as img:
|
||||
size = max(img.width, img.height)
|
||||
frame_thick = int(size * 0.0054)
|
||||
inner_size = size - 2 * frame_thick
|
||||
resized_img = img.resize((inner_size, inner_size), Image.LANCZOS)
|
||||
framed = Image.new("RGB", (size, size), "white")
|
||||
framed.paste(resized_img, (frame_thick, frame_thick))
|
||||
landscape_w = int(size * 1.5)
|
||||
caption_h = int(size * 0.3)
|
||||
canvas_h = framed.height + caption_h
|
||||
canvas = Image.new("RGB", (landscape_w, canvas_h), "black")
|
||||
# the above logic didnt even work, fml
|
||||
fx = (landscape_w - framed.width) // 2
|
||||
canvas.paste(framed, (fx, 0))
|
||||
|
||||
draw = ImageDraw.Draw(canvas)
|
||||
|
||||
title = subtitle = None
|
||||
for _ in range(20):
|
||||
t = markov_model.make_sentence(tries=100, max_words=4)
|
||||
s = markov_model.make_sentence(tries=100, max_words=5)
|
||||
if t and s and t != s:
|
||||
title = t.upper()
|
||||
subtitle = s.capitalize()
|
||||
break
|
||||
if not title: title = "DEMOTIVATOR"
|
||||
if not subtitle: subtitle = "no text generated"
|
||||
|
||||
title_sz = int(caption_h * 0.4)
|
||||
sub_sz = int(caption_h * 0.25)
|
||||
title_font = load_tnr(title_sz)
|
||||
sub_font = load_tnr(sub_sz)
|
||||
|
||||
bbox = draw.textbbox((0, 0), title, font=title_font)
|
||||
txw, txh = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
tx = (landscape_w - txw) // 2
|
||||
ty = framed.height + int(caption_h * 0.1)
|
||||
draw_text_with_outline(draw, title, tx, ty, title_font)
|
||||
|
||||
bbox = draw.textbbox((0, 0), subtitle, font=sub_font)
|
||||
sxw, sxh = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
sx = (landscape_w - sxw) // 2
|
||||
sy = ty + txh + int(caption_h * 0.05)
|
||||
for ox, oy in [(-1, -1), (1, -1), (-1, 1), (1, 1)]:
|
||||
draw.text((sx + ox, sy + oy), subtitle, font=sub_font, fill="black")
|
||||
draw.text((sx, sy), subtitle, font=sub_font, fill="#AAAAAA")
|
||||
|
||||
canvas.save(input_image_path)
|
||||
return input_image_path
|
||||
|
||||
attempt += 1
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue