From e5b91cda9b6dadc8123b9179fbd7986b6453cba9 Mon Sep 17 00:00:00 2001 From: owl Date: Tue, 18 Feb 2025 18:14:27 +0700 Subject: [PATCH] fix error message --- tgbot/shit/render.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tgbot/shit/render.py b/tgbot/shit/render.py index e520c9c..729f18a 100644 --- a/tgbot/shit/render.py +++ b/tgbot/shit/render.py @@ -69,18 +69,21 @@ def render_text_on_image(input_image_path, text_to_draw, output_image_path=None, WIDTH = 29 HEIGHT = 10 +EMPTY_DOT = "◌" +FILLED_DOT = "●" + def image_to_string(image_file): img = Image.open(image_file) - img = img.resize((WIDTH, HEIGHT), Image.Resampling.NEAREST) + img = img.resize((WIDTH, HEIGHT), Image.Resampling.LANCZOS) img = img.convert("1") # Get image dimensions width, height = img.size if width != WIDTH or height != HEIGHT: - raise ValueError("The image must be exactly 22x9 pixels.") + raise ValueError(f"The image must be exactly {WIDTH}x{HEIGHT} pixels.") # Create the string representation pixel_string = "" @@ -89,9 +92,9 @@ def image_to_string(image_file): # Get the pixel value (0 for black, 255 for white) pixel = img.getpixel((x, y)) if pixel == 0: # Black pixel - pixel_string += "◌" + pixel_string += EMPTY_DOT else: # White pixel - pixel_string += "●" + pixel_string += FILLED_DOT pixel_string += " " # New line for each row return pixel_string