This commit is contained in:
2025-11-18 13:07:01 +03:00
parent 46bba1ef85
commit 087af690dd
2 changed files with 14 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import Response, HTMLResponse, FileResponse, StreamingResponse
from typing import Dict, Any
from fastapi.responses import Response, HTMLResponse, StreamingResponse
from contextlib import asynccontextmanager
import requests, uvicorn, json
import threading, queue
@@ -17,7 +16,6 @@ import io, os, platform, time
import xml.etree.ElementTree as ET
import re
from PIL import Image, ImageDraw, ImageFont
import base64
from io import BytesIO
@@ -3433,13 +3431,19 @@ def get_image(points, bib, count_point):
# --- подпись Q{period} по центру ---
label = f"Q{period}"
bbox = draw.textbbox((0, 0), label, font=font)
text_w = bbox[2] - bbox[0]
text_h = bbox[3] - bbox[1]
# узнаём размер текста (Pillow 10+ — textbbox, старые — textsize)
try:
bbox = draw.textbbox((0, 0), label, font=font)
text_w = bbox[2] - bbox[0]
text_h = bbox[3] - bbox[1]
except AttributeError:
# fallback для старых версий Pillow
text_w, text_h = draw.textsize(label, font=font)
# центрируем относительно точки (px, py)
text_x = px - text_w // 2
text_y = py - text_h // 2
# центр иконки = центр текста
center_x, center_y = px, py
text_x = center_x - text_w // 2
text_y = center_y - text_h // 2
# тень
draw.text((text_x + 1, text_y + 1), label, font=font, fill=(0, 0, 0, 255))