diff --git a/get_data.py b/get_data.py index 6d8e99a..7635db7 100644 --- a/get_data.py +++ b/get_data.py @@ -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)) diff --git a/requirements.txt b/requirements.txt index d75e3d5..6928849 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ python-telegram-handler python-dotenv --extra-index-url https://git.tvstart.ru/api/packages/lexx/pypi/simple nasio -pillow>=12.0.0 \ No newline at end of file +pillow \ No newline at end of file