diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 222fbf4..98b65a2 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -38,6 +38,9 @@ storymodemethod= { optional = true, default = 1, example = 1, explanation = "Sty storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" } resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" } +text_size = { optional = false, default = 56, example = 75, explantation = "Sets the font size for the captions" } +text_padding = { optional = false, default = 5, example = 10, explantation = "Sets the line spacing for the captions" } +text_wrap = { optional = false, default = 30, example = 40, explantation = "Sets the number of characters per line, before it is wrapped to another line" } zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger.", type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } [settings.background] diff --git a/utils/imagenarator.py b/utils/imagenarator.py index 1a4ef42..779e208 100644 --- a/utils/imagenarator.py +++ b/utils/imagenarator.py @@ -3,6 +3,8 @@ import textwrap import os import json +from utils import settings + from PIL import Image, ImageDraw, ImageFont from rich.progress import track from TTS.engine_wrapper import process_text @@ -72,7 +74,7 @@ def draw_multiple_line_text( y += line_height + padding -def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) -> None: +def imagemaker(theme, reddit_obj: dict, txtclr, transparent=False) -> None: """ Render Images for video """ @@ -81,24 +83,25 @@ def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) -> id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) if transparent: - font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100) - tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100) + font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), int(settings.config["settings"]["text_size"])) # changed + tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), int(settings.config["settings"]["text_size"])) # changed else: - tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100) # for title - font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), 100) - size = (1920, 1080) + tfont = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), int(settings.config["settings"]["text_size"])) # for title # changed + font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), int(settings.config["settings"]["text_size"])) # changed + + size = (int(settings.config["settings"]["resolution_w"]), int(settings.config["settings"]["resolution_h"])) image = Image.new("RGBA", size, theme) # for title - draw_multiple_line_text(image, title, tfont, txtclr, padding, wrap=30, transparent=transparent) + draw_multiple_line_text(image, perform_text_replacements(title), tfont, txtclr, int(settings.config["settings"]["text_padding"]), wrap=int(settings.config["settings"]["text_wrap"]), transparent=transparent) image.save(f"assets/temp/{id}/png/title.png") for idx, text in track(enumerate(texts), "💬 Rendering captions...", total=len(texts)): image = Image.new("RGBA", size, theme) text = process_text(text, False) - draw_multiple_line_text(image, perform_text_replacements(text), font, txtclr, padding, wrap=30, transparent=transparent) + draw_multiple_line_text(image, perform_text_replacements(text), font, txtclr, int(settings.config["settings"]["text_padding"]), wrap=int(settings.config["settings"]["text_wrap"]), transparent=transparent) image.save(f"assets/temp/{id}/png/img{idx}.png") print_substep("Captions rendered successfully!", style="bold green") diff --git a/utils/version.py b/utils/version.py index 0818c87..ba13de2 100644 --- a/utils/version.py +++ b/utils/version.py @@ -4,18 +4,21 @@ from utils.console import print_step def checkversion(__VERSION__: str): - response = requests.get( - "https://api.github.com/repos/elebumm/RedditVideoMakerBot/releases/latest" - ) - latestversion = response.json()["tag_name"] - if __VERSION__ == latestversion: - print_step(f"You are using the newest version ({__VERSION__}) of the bot") - return True - elif __VERSION__ < latestversion: - print_step( - f"You are using an older version ({__VERSION__}) of the bot. Download the newest version ({latestversion}) from https://github.com/elebumm/RedditVideoMakerBot/releases/latest" - ) - else: - print_step( - f"Welcome to the test version ({__VERSION__}) of the bot. Thanks for testing and feel free to report any bugs you find." + try: + response = requests.get( + "https://api.github.com/repos/elebumm/RedditVideoMakerBot/releases/latest" ) + latestversion = response.json()["tag_name"] + if __VERSION__ == latestversion: + print_step(f"You are using the newest version ({__VERSION__}) of the bot") + return True + elif __VERSION__ < latestversion: + print_step( + f"You are using an older version ({__VERSION__}) of the bot. Download the newest version ({latestversion}) from https://github.com/elebumm/RedditVideoMakerBot/releases/latest" + ) + else: + print_step( + f"Welcome to the test version ({__VERSION__}) of the bot. Thanks for testing and feel free to report any bugs you find." + ) + except: + pass