Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你要的高度调整 #1

Closed
jcjrobert opened this issue May 14, 2022 · 1 comment
Closed

你要的高度调整 #1

jcjrobert opened this issue May 14, 2022 · 1 comment

Comments

@jcjrobert
Copy link

jcjrobert commented May 14, 2022

更改前

async def self_adaption_font_of_text(font_filename, default_font_size: int, text: str):
    """
    获取一段文本所占的宽度像素值
    返回字符画的 width, height
    """
    ttfont = ImageFont.truetype(font_filename, default_font_size)
    lines = text.split("\n")
    w = ttfont.getsize(lines[2])[0]

    return (
        ttfont,
        w,
        default_font_size * len(lines) + int(1.2 * len(lines)),
    )  # 高度不会搞,1.2 是瞎jb调的,等一个大佬(

更改后

async def self_adaption_font_of_text(font_filename, default_font_size: int, text: str):
    """
    获取一段文本所占的宽度像素值
    返回字符画的 width, height
    """
    ttfont = ImageFont.truetype(font_filename, default_font_size)
    w, h = ttfont.getsize_multiline(text.strip())

    return ttfont,w,h
@1umine
Copy link
Owner

1umine commented May 14, 2022

更改前

async def self_adaption_font_of_text(font_filename, default_font_size: int, text: str):
    """
    获取一段文本所占的宽度像素值
    返回字符画的 width, height
    """
    ttfont = ImageFont.truetype(font_filename, default_font_size)
    lines = text.split("\n")
    w = ttfont.getsize(lines[2])[0]

    return (
        ttfont,
        w,
        default_font_size * len(lines) + int(1.2 * len(lines)),
    )  # 高度不会搞,1.2 是瞎jb调的,等一个大佬(

更改后

async def self_adaption_font_of_text(font_filename, default_font_size: int, text: str):
    """
    获取一段文本所占的宽度像素值
    返回字符画的 width, height
    """
    ttfont = ImageFont.truetype(font_filename, default_font_size)
    w, h = ttfont.getsize_multiline(text.strip())

    return ttfont,w,h

收到!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants