add second maket
This commit is contained in:
parent
6afc30570f
commit
f14b1a8209
3 changed files with 12 additions and 2 deletions
|
|
@ -26,6 +26,12 @@ TEMPLATES = {
|
||||||
"padding": 20,
|
"padding": 20,
|
||||||
"label": "Владимир Владимирович Путин самый лучший президент",
|
"label": "Владимир Владимирович Путин самый лучший президент",
|
||||||
},
|
},
|
||||||
|
"2": {
|
||||||
|
"path": BASE_DIR / "maket" / "2.png",
|
||||||
|
"anchor": (40, 40),
|
||||||
|
"box_size": (582, 346),
|
||||||
|
"label": "Макет 2",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Расписание ---
|
# --- Расписание ---
|
||||||
|
|
|
||||||
8
main.py
8
main.py
|
|
@ -262,8 +262,12 @@ def generate_maket(text: str, template_id: str = "1") -> BytesIO:
|
||||||
raise FileNotFoundError(f"Шаблон {template_id} не найден")
|
raise FileNotFoundError(f"Шаблон {template_id} не найден")
|
||||||
|
|
||||||
with Image.open(tpl["path"]).convert("RGB") as img:
|
with Image.open(tpl["path"]).convert("RGB") as img:
|
||||||
anchor, padding = tpl["anchor"], tpl["padding"]
|
anchor = tpl["anchor"]
|
||||||
max_w, max_h = img.width - anchor[0] - padding, img.height - anchor[1] - padding
|
if "box_size" in tpl:
|
||||||
|
max_w, max_h = tpl["box_size"]
|
||||||
|
else:
|
||||||
|
padding = tpl.get("padding", 0)
|
||||||
|
max_w, max_h = img.width - anchor[0] - padding, img.height - anchor[1] - padding
|
||||||
|
|
||||||
font, lines, stroke, spacing = fit_text_in_box(text, max_w, max_h)
|
font, lines, stroke, spacing = fit_text_in_box(text, max_w, max_h)
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
|
||||||
BIN
maket/2.png
Normal file
BIN
maket/2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 701 KiB |
Loading…
Reference in a new issue