|
|
|
@ -108,33 +108,56 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str:
|
|
|
|
|
exit(1)
|
|
|
|
|
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_fancy_thumbnail(image, text, text_color, padding, wrap=35):
|
|
|
|
|
print_step(f"Creating fancy thumbnail for: {text}")
|
|
|
|
|
font_title_size = 47
|
|
|
|
|
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
|
|
|
|
image_width, image_height = image.size
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap)
|
|
|
|
|
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 30
|
|
|
|
|
y = (
|
|
|
|
|
(image_height / 2)
|
|
|
|
|
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
|
|
|
|
+ 30
|
|
|
|
|
)
|
|
|
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
|
|
|
|
username_font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 30)
|
|
|
|
|
draw.text((205, 825), settings.config["settings"]["channel_name"], font=username_font, fill=text_color, align="left")
|
|
|
|
|
draw.text(
|
|
|
|
|
(205, 825),
|
|
|
|
|
settings.config["settings"]["channel_name"],
|
|
|
|
|
font=username_font,
|
|
|
|
|
fill=text_color,
|
|
|
|
|
align="left",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if len(lines) == 3:
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap+10)
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap + 10)
|
|
|
|
|
font_title_size = 40
|
|
|
|
|
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
|
|
|
|
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 35
|
|
|
|
|
y = (
|
|
|
|
|
(image_height / 2)
|
|
|
|
|
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
|
|
|
|
+ 35
|
|
|
|
|
)
|
|
|
|
|
elif len(lines) == 4:
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap+10)
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap + 10)
|
|
|
|
|
font_title_size = 35
|
|
|
|
|
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
|
|
|
|
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 40
|
|
|
|
|
y = (
|
|
|
|
|
(image_height / 2)
|
|
|
|
|
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
|
|
|
|
+ 40
|
|
|
|
|
)
|
|
|
|
|
elif len(lines) > 4:
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap+10)
|
|
|
|
|
lines = textwrap.wrap(text, width=wrap + 10)
|
|
|
|
|
font_title_size = 30
|
|
|
|
|
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), font_title_size)
|
|
|
|
|
y = (image_height / 2) - (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + 30
|
|
|
|
|
y = (
|
|
|
|
|
(image_height / 2)
|
|
|
|
|
- (((font.getsize(text)[1] + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
|
|
|
|
|
+ 30
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
_, line_height = font.getsize(line)
|
|
|
|
@ -240,7 +263,7 @@ def make_final_video(
|
|
|
|
|
image_clips = list()
|
|
|
|
|
|
|
|
|
|
Path(f"assets/temp/{reddit_id}/png").mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Copyright 2024 beingbored (aka. Tim), MIT License, permission granted to use, copy, modify, and distribute.
|
|
|
|
|
# get the title_template image and draw a text in the middle part of it with the title of the thread
|
|
|
|
|
title_template = Image.open("assets/title_template.png")
|
|
|
|
@ -253,9 +276,7 @@ def make_final_video(
|
|
|
|
|
padding = 5
|
|
|
|
|
|
|
|
|
|
# create_fancy_thumbnail(image, text, text_color, padding
|
|
|
|
|
title_img = create_fancy_thumbnail(
|
|
|
|
|
title_template, title, font_color, padding
|
|
|
|
|
)
|
|
|
|
|
title_img = create_fancy_thumbnail(title_template, title, font_color, padding)
|
|
|
|
|
|
|
|
|
|
title_img.save(f"assets/temp/{reddit_id}/png/title.png")
|
|
|
|
|
|
|
|
|
|