Skip to content

Commit

Permalink
TypeError: cannot unpack non-iterable float object
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhhu authored Aug 16, 2023
1 parent a0f8cbd commit 875f0d2
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions plugins/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,11 @@ async def logo_func(event):


class LogoHelper:
@staticmethod
def get_text_size(text, image, font):
im = Image.new("RGB", (image.width, image.height))
draw = ImageDraw.Draw(im)
return draw.textlength(text, font)

@staticmethod
def find_font_size(text, font, image, target_width_ratio):
tested_font_size = 100
tested_font = ImageFont.truetype(font, tested_font_size)
observed_width, observed_height = LogoHelper.get_text_size(
text, image, tested_font
)
observed_width, observed_height = tested_font.getsize(text)
estimated_font_size = (
tested_font_size / (observed_width /
image.width) * target_width_ratio
Expand All @@ -118,7 +110,7 @@ def make_logo(imgpath, text, funt, **args):
draw = ImageDraw.Draw(img)
font_size = LogoHelper.find_font_size(text, funt, img, width_ratio)
font = ImageFont.truetype(funt, font_size)
w, h = draw.textlength(text, font=font)
w, h = font.getsize(text)
draw.text(
((width - w) / 2, (height - h) / 2),
text,
Expand Down

0 comments on commit 875f0d2

Please sign in to comment.