From c32314471bc42b923d26a5be7df8a721be53a587 Mon Sep 17 00:00:00 2001 From: electro199 <109358640+electro199@users.noreply.github.com> Date: Mon, 9 Jun 2025 12:56:20 +0500 Subject: [PATCH] fixed canvas --- utils/imagenarator.py | 13 +++++++++---- video_creation/screenshot_downloader.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/imagenarator.py b/utils/imagenarator.py index 509882d..4520fb3 100644 --- a/utils/imagenarator.py +++ b/utils/imagenarator.py @@ -19,7 +19,9 @@ def draw_multiple_line_text( font_height = getheight(font, text) image_width, image_height = image.size lines = textwrap.wrap(text, width=wrap) - y = (image_height / 2) - (((font_height + (len(lines) * padding) / len(lines)) * len(lines)) / 2) + y = (image_height / 2) - ( + ((font_height + (len(lines) * padding) / len(lines)) * len(lines)) / 2 + ) for line in lines: line_width, line_height = getsize(font, line) if transparent: @@ -53,7 +55,9 @@ 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, size: tuple[int, int], padding=5, transparent=False +) -> None: """ Render Images for video """ @@ -64,12 +68,13 @@ def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) -> font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100) else: font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), 100) - size = (1920, 1080) image = Image.new("RGBA", size, theme) for idx, text in track(enumerate(texts), "Rendering Image"): image = Image.new("RGBA", size, theme) text = process_text(text, False) - draw_multiple_line_text(image, text, font, txtclr, padding, wrap=30, transparent=transparent) + draw_multiple_line_text( + image, text, font, txtclr, padding, wrap=30, transparent=transparent + ) image.save(f"assets/temp/{id}/png/img{idx}.png") diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 6b56e99..57675b6 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -66,6 +66,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): theme=bgcolor, reddit_obj=reddit_object, txtclr=txtcolor, + size=(W,H), transparent=transparent, )