mod letter
This commit is contained in:
parent
dd65611fff
commit
81b89a81f5
|
|
@ -359,24 +359,19 @@ class UsersTable:
|
|||
text_color = (255, 255, 255)
|
||||
|
||||
# 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 = ImageFont.truetype(font_path, font_size)
|
||||
while font.getbbox(text)[2] < target_percentage * image_size[0] and \
|
||||
font.getbbox(text)[3] < target_percentage * image_size[1]:
|
||||
font = ImageFont.load_default().font.copy()
|
||||
while True:
|
||||
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 = ImageFont.truetype(font_path, font_size)
|
||||
return font_size - 1
|
||||
|
||||
try:
|
||||
font_path = "arial.ttf"
|
||||
font_size = get_font_size(size, letter, font_path)
|
||||
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
|
||||
font_size = get_font_size(size, letter)
|
||||
font = ImageFont.load_default().font.copy()
|
||||
font.set_size(font_size)
|
||||
|
||||
# Obliczanie pozycji tekstu
|
||||
bbox = font.getbbox(letter)
|
||||
|
|
|
|||
Loading…
Reference in New Issue