Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,7 +106,7 @@ def process_image(image, text):
|
|
| 106 |
|
| 107 |
# Dynamically set font size based on the white paper dimensions
|
| 108 |
try:
|
| 109 |
-
font_size = min(int(box_height * 0.
|
| 110 |
font = ImageFont.truetype(FONT_PATH, size=font_size)
|
| 111 |
logging.debug("Font loaded successfully.")
|
| 112 |
except Exception as e:
|
|
@@ -123,7 +123,7 @@ def process_image(image, text):
|
|
| 123 |
line_height = (text_draw.textbbox((0, 0), "Hg", font=font)[3] - text_draw.textbbox((0, 0), "Hg", font=font)[1]) * 1.2
|
| 124 |
total_text_height = len(lines) * line_height
|
| 125 |
while total_text_height > box_height:
|
| 126 |
-
font_size = font.size -
|
| 127 |
if font_size < 10: # Set a minimum font size
|
| 128 |
break
|
| 129 |
font = ImageFont.truetype(FONT_PATH, size=font_size)
|
|
|
|
| 106 |
|
| 107 |
# Dynamically set font size based on the white paper dimensions
|
| 108 |
try:
|
| 109 |
+
font_size = min(int(box_height * 0.7), int(box_width / 10))
|
| 110 |
font = ImageFont.truetype(FONT_PATH, size=font_size)
|
| 111 |
logging.debug("Font loaded successfully.")
|
| 112 |
except Exception as e:
|
|
|
|
| 123 |
line_height = (text_draw.textbbox((0, 0), "Hg", font=font)[3] - text_draw.textbbox((0, 0), "Hg", font=font)[1]) * 1.2
|
| 124 |
total_text_height = len(lines) * line_height
|
| 125 |
while total_text_height > box_height:
|
| 126 |
+
font_size = font.size - 4 # Reduce font size
|
| 127 |
if font_size < 10: # Set a minimum font size
|
| 128 |
break
|
| 129 |
font = ImageFont.truetype(FONT_PATH, size=font_size)
|