fancy title screen

pull/2051/head
cyteon 6 months ago
parent 64f2322ba0
commit 209630832d

3
.gitignore vendored

@ -231,7 +231,8 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
assets/
assets/temp
assets/backgrounds
/.vscode
out
.DS_Store

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

@ -3,14 +3,17 @@ import os
import re
import tempfile
import threading
import textwrap
import time
from pathlib import Path
from os.path import exists # Needs to be imported specifically
from typing import Final
from typing import Tuple, Dict
import ffmpeg
import translators
from PIL import Image
from PIL import ImageDraw, ImageFont, Image
from rich.console import Console
from rich.progress import track
@ -105,6 +108,41 @@ 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
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")
if len(lines) == 3:
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
elif len(lines) == 4:
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
elif len(lines) > 4:
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
for line in lines:
_, line_height = font.getsize(line)
draw.text((120, y), line, font=font, fill=text_color, align="left")
y += line_height + padding
return image
def merge_background_audio(audio: ffmpeg, reddit_id: str):
"""Gather an audio and merge with assets/backgrounds/background.mp3
@ -201,6 +239,28 @@ 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")
title = reddit_obj["thread_title"]
title = name_normalize(title)
font_color = "#000000"
padding = 5
# create_fancy_thumbnail(image, text, text_color, padding
title_img = create_fancy_thumbnail(
title_template, title, font_color, padding
)
title_img.save(f"assets/temp/{reddit_id}/png/title.png")
# Copyright end
image_clips.insert(
0,
ffmpeg.input(f"assets/temp/{reddit_id}/png/title.png")["v"].filter(

@ -68,6 +68,10 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
transparent=transparent,
)
if settings.config["settings"]["storymodemethod"] == 1:
print_substep("Storymodemethod 1 does not need screnshoots")
return
screenshot_num: int
with sync_playwright() as p:
print_substep("Launching Headless Browser...")

Loading…
Cancel
Save