mod letter
This commit is contained in:
parent
dd65611fff
commit
81b89a81f5
|
|
@ -359,24 +359,19 @@ class UsersTable:
|
||||||
text_color = (255, 255, 255)
|
text_color = (255, 255, 255)
|
||||||
|
|
||||||
# Funkcja do obliczania rozmiaru czcionki
|
# Funkcja do obliczania rozmiaru czcionki
|
||||||
def get_font_size(image_size, text, font_path, target_percentage=0.8):
|
def get_font_size(image_size, text, target_percentage=0.8):
|
||||||
font_size = 1
|
font_size = 1
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.load_default().font.copy()
|
||||||
while font.getbbox(text)[2] < target_percentage * image_size[0] and \
|
while True:
|
||||||
font.getbbox(text)[3] < target_percentage * image_size[1]:
|
font.set_size(font_size)
|
||||||
|
bbox = font.getbbox(text)
|
||||||
|
if bbox[2] > target_percentage * image_size[0] or bbox[3] > target_percentage * image_size[1]:
|
||||||
|
return font_size - 1
|
||||||
font_size += 1
|
font_size += 1
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
|
||||||
return font_size - 1
|
|
||||||
|
|
||||||
try:
|
font_size = get_font_size(size, letter)
|
||||||
font_path = "arial.ttf"
|
font = ImageFont.load_default().font.copy()
|
||||||
font_size = get_font_size(size, letter, font_path)
|
font.set_size(font_size)
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
|
||||||
except IOError:
|
|
||||||
# Jeśli Arial nie jest dostępny, użyj czcionki domyślnej
|
|
||||||
font = ImageFont.load_default()
|
|
||||||
# Dla czcionki domyślnej możemy potrzebować innej metody określania rozmiaru
|
|
||||||
font_size = min(size) // 2 # To jest przybliżenie, może wymagać dostosowania
|
|
||||||
|
|
||||||
# Obliczanie pozycji tekstu
|
# Obliczanie pozycji tekstu
|
||||||
bbox = font.getbbox(letter)
|
bbox = font.getbbox(letter)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue