fix error message

This commit is contained in:
Owl 2025-02-18 18:14:27 +07:00
parent a10d6568f1
commit e5b91cda9b

View File

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