fixed canvas

pull/2336/head
electro199 3 months ago
parent 64bf647de9
commit c32314471b

@ -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")

@ -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,
)

Loading…
Cancel
Save