Skip to content

getbbox incorrect when string contains new line character #7013

@vanviethieuanh

Description

@vanviethieuanh

What did you do?

So I use the getbbox to calculate the width and height of my string with a specific font. The string includes the \n character and it split the line into 2.

What did you expect to happen?

The string renders well and has a width of about 7xx pixels which is what I want. And I expect the getbbox function returns the same value.

What actually happened?

However, the result I got from getbbox is 1555 pixels which might be the width of no break line text.

What are your OS, Python, and Pillow versions?

  • OS: Windows 10 Enterprise
  • Python: Python 3.10.10
  • Pillow: 9.4.0
text = "Age is an issue of mind over matter.\nIf you don't mind, it doesn't matter."
_, _, text_width, text_height = FONT.getbbox(text)
# text_width = 1555

image
The size of the image is 1080*1080 so there is no way that the text width is 1555.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions