mirror of
https://github.com/kemayo/leech
synced 2026-04-19 11:00:47 +02:00
Cover text: outlined
This commit is contained in:
parent
701e196359
commit
c0e903c3da
1 changed files with 16 additions and 4 deletions
20
cover.py
20
cover.py
|
|
@ -13,13 +13,12 @@ def make_cover(title, author, width=600, height=800, fontname="Helvetica", fonts
|
|||
|
||||
font = ImageFont.truetype(font=fontname, size=fontsize)
|
||||
title_size = draw.textsize(title, font=font)
|
||||
draw.text(((width - title_size[0]) / 2, 100), title, textcolor, 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 = ImageFont.truetype(font=fontname, size=fontsize - 2)
|
||||
author_size = draw.textsize(author, font=font)
|
||||
draw.text(((width - author_size[0]) / 2, 100 + title_size[1] + 70), author, textcolor, font=font)
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw_text_outlined(draw, ((width - author_size[0]) / 2, 100 + title_size[1] + 70), author, textcolor, font=font)
|
||||
|
||||
output = BytesIO()
|
||||
img.save(output, "PNG")
|
||||
|
|
@ -29,6 +28,19 @@ def make_cover(title, author, width=600, height=800, fontname="Helvetica", fonts
|
|||
return output
|
||||
|
||||
|
||||
def draw_text_outlined(draw, xy, text, fill=None, font=None, anchor=None):
|
||||
x, y = xy
|
||||
|
||||
# Outline
|
||||
draw.text((x - 1, y), text=text, fill=(0, 0, 0), font=font, anchor=anchor)
|
||||
draw.text((x + 1, y), text=text, fill=(0, 0, 0), font=font, anchor=anchor)
|
||||
draw.text((x, y - 1), text=text, fill=(0, 0, 0), font=font, anchor=anchor)
|
||||
draw.text((x, y + 1), text=text, fill=(0, 0, 0), font=font, anchor=anchor)
|
||||
|
||||
# Fill
|
||||
draw.text(xy, text=text, fill=fill, font=font, anchor=anchor)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
f = make_cover('Test of a Title which is quite long and will require multiple lines', 'Some Dude')
|
||||
with open('output.png', 'wb') as out:
|
||||
|
|
|
|||
Loading…
Reference in a new issue