Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -107,7 +107,7 @@ def crop_to_region(img, lat, lon, zoom=1.5):
|
|
| 107 |
cropped = img.crop((x1, y1, x2, y2))
|
| 108 |
return cropped.resize((img_width, img_height), Image.Resampling.LANCZOS)
|
| 109 |
|
| 110 |
-
def draw_text_with_outline(draw, text, pos, font_size=20):
|
| 111 |
"""Draw text with outline for visibility."""
|
| 112 |
try:
|
| 113 |
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", font_size)
|
|
@@ -115,6 +115,14 @@ def draw_text_with_outline(draw, text, pos, font_size=20):
|
|
| 115 |
font = ImageFont.load_default()
|
| 116 |
|
| 117 |
x, y = pos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
# Draw outline
|
| 119 |
for dx, dy in [(-1,-1), (-1,1), (1,-1), (1,1)]:
|
| 120 |
draw.text((x+dx, y+dy), text, fill='black', font=font)
|
|
|
|
| 107 |
cropped = img.crop((x1, y1, x2, y2))
|
| 108 |
return cropped.resize((img_width, img_height), Image.Resampling.LANCZOS)
|
| 109 |
|
| 110 |
+
def draw_text_with_outline(draw, text, pos, font_size=20, center=False):
|
| 111 |
"""Draw text with outline for visibility."""
|
| 112 |
try:
|
| 113 |
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", font_size)
|
|
|
|
| 115 |
font = ImageFont.load_default()
|
| 116 |
|
| 117 |
x, y = pos
|
| 118 |
+
if center:
|
| 119 |
+
# Get text size for centering
|
| 120 |
+
bbox = draw.textbbox((0, 0), text, font=font)
|
| 121 |
+
text_width = bbox[2] - bbox[0]
|
| 122 |
+
text_height = bbox[3] - bbox[1]
|
| 123 |
+
x = x - text_width // 2
|
| 124 |
+
y = y - text_height // 2
|
| 125 |
+
|
| 126 |
# Draw outline
|
| 127 |
for dx, dy in [(-1,-1), (-1,1), (1,-1), (1,1)]:
|
| 128 |
draw.text((x+dx, y+dy), text, fill='black', font=font)
|