mirror of
https://github.com/kemayo/leech
synced 2026-02-06 23:01:31 +01:00
Pillow 10 removed the deprecated ImageDraw.textsize
This commit is contained in:
parent
2467ee26fe
commit
9171672663
1 changed files with 8 additions and 2 deletions
|
|
@ -16,12 +16,12 @@ def make_cover(title, author, width=600, height=800, fontname="Helvetica", fonts
|
|||
author = textwrap.fill(author, wrapat)
|
||||
|
||||
font = _safe_font(fontname, size=fontsize)
|
||||
title_size = draw.textsize(title, font=font)
|
||||
title_size = textsize(draw, title, font=font)
|
||||
draw_text_outlined(draw, ((width - title_size[0]) / 2, 100), title, textcolor, font=font)
|
||||
# draw.text(((width - title_size[0]) / 2, 100), title, textcolor, font=font)
|
||||
|
||||
font = _safe_font(fontname, size=fontsize - 2)
|
||||
author_size = draw.textsize(author, font=font)
|
||||
author_size = textsize(draw, author, font=font)
|
||||
draw_text_outlined(draw, ((width - author_size[0]) / 2, 100 + title_size[1] + 70), author, textcolor, font=font)
|
||||
|
||||
output = BytesIO()
|
||||
|
|
@ -73,6 +73,12 @@ def _safe_font(preferred, *args, **kwargs):
|
|||
return ImageFont.load_default()
|
||||
|
||||
|
||||
def textsize(draw, text, **kwargs):
|
||||
left, top, right, bottom = draw.multiline_textbbox((0, 0), text, **kwargs)
|
||||
width, height = right - left, bottom - top
|
||||
return width, height
|
||||
|
||||
|
||||
def draw_text_outlined(draw, xy, text, fill=None, font=None, anchor=None):
|
||||
x, y = xy
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue