Renzo
commited on
Commit
·
5080c58
1
Parent(s):
69b36c1
Adjust font size and padding in route_utils for improved text rendering
Browse files- route_utils.py +5 -4
route_utils.py
CHANGED
|
@@ -56,9 +56,10 @@ def load_image_with_title(image_path, custom_title=None):
|
|
| 56 |
from PIL import ImageDraw, ImageFont
|
| 57 |
draw = ImageDraw.Draw(image)
|
| 58 |
|
| 59 |
-
# Try to use a nice font,
|
|
|
|
| 60 |
try:
|
| 61 |
-
font = ImageFont.truetype("Arial.ttf",
|
| 62 |
except:
|
| 63 |
font = ImageFont.load_default()
|
| 64 |
|
|
@@ -66,10 +67,10 @@ def load_image_with_title(image_path, custom_title=None):
|
|
| 66 |
text_bbox = draw.textbbox((0, 0), custom_title, font=font)
|
| 67 |
text_width = text_bbox[2] - text_bbox[0]
|
| 68 |
x = (image.width - text_width) // 2
|
| 69 |
-
y =
|
| 70 |
|
| 71 |
# Add background rectangle for better readability
|
| 72 |
-
padding =
|
| 73 |
draw.rectangle([x-padding, y-padding, x+text_width+padding, y+text_bbox[3]+padding],
|
| 74 |
fill="white", outline="black")
|
| 75 |
draw.text((x, y), custom_title, fill="black", font=font)
|
|
|
|
| 56 |
from PIL import ImageDraw, ImageFont
|
| 57 |
draw = ImageDraw.Draw(image)
|
| 58 |
|
| 59 |
+
# Try to use a nice font, scaled to image size
|
| 60 |
+
font_size = max(16, image.width // 25) # Responsive font size
|
| 61 |
try:
|
| 62 |
+
font = ImageFont.truetype("Arial.ttf", font_size)
|
| 63 |
except:
|
| 64 |
font = ImageFont.load_default()
|
| 65 |
|
|
|
|
| 67 |
text_bbox = draw.textbbox((0, 0), custom_title, font=font)
|
| 68 |
text_width = text_bbox[2] - text_bbox[0]
|
| 69 |
x = (image.width - text_width) // 2
|
| 70 |
+
y = 5 # Reduced margin for smaller images
|
| 71 |
|
| 72 |
# Add background rectangle for better readability
|
| 73 |
+
padding = 3 # Smaller padding for smaller images
|
| 74 |
draw.rectangle([x-padding, y-padding, x+text_width+padding, y+text_bbox[3]+padding],
|
| 75 |
fill="white", outline="black")
|
| 76 |
draw.text((x, y), custom_title, fill="black", font=font)
|