Spaces:
Runtime error
Runtime error
Update utils/polygon_utils.py
Browse files- utils/polygon_utils.py +3 -1
utils/polygon_utils.py
CHANGED
|
@@ -48,7 +48,9 @@ def draw_wrapped_text(image, polygon, text, font_path, fill="black"):
|
|
| 48 |
if font_size <= 10:
|
| 49 |
break
|
| 50 |
font = ImageFont.truetype(font_path, font_size)
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
wrapped = textwrap.fill(text, width=max_chars)
|
| 53 |
|
| 54 |
# Center text in box
|
|
|
|
| 48 |
if font_size <= 10:
|
| 49 |
break
|
| 50 |
font = ImageFont.truetype(font_path, font_size)
|
| 51 |
+
char_bbox = font.getbbox("A") # (x0, y0, x1, y1)
|
| 52 |
+
char_width = char_bbox[2] - char_bbox[0]
|
| 53 |
+
max_chars = max(1, int(box_width / (char_width + 1)))
|
| 54 |
wrapped = textwrap.fill(text, width=max_chars)
|
| 55 |
|
| 56 |
# Center text in box
|