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

Describe difference between font size and bbox #7806

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ Previous code::

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width, height = draw.textsize("Hello world")
width, height = draw.textsize("Hello world", font)

width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld", font)

Use instead::

Expand All @@ -247,11 +247,19 @@ Use instead::

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width = draw.textlength("Hello world")
width = draw.textlength("Hello world", font)

left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld")
left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld", font)
width, height = right - left, bottom - top

Previously, the ``size`` methods returned a ``height`` that included the vertical
offset of the text, while the new ``bbox`` methods distinguish this as a ``top``
offset.

.. image:: ./example/size_vs_bbox.png
:alt: Demonstration of size height vs bbox top and bottom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than saying what the image is, could you describe what the image conveys?

Imagine it read aloud to you when you can't see the image.

https://accessibility.huit.harvard.edu/describe-content-images

Copy link
Member Author

@radarhere radarhere Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a commit.

In bbox methods, top measures the vertical distance above the text, while bottom measures that plus the vertical distance of the text itself. In size methods, height also measures the vertical distance above the text plus the vertical distance of the text itself.

I don't really like it, but it was a struggle to explain the meaning of 'height', 'top' and 'bottom' without using those words in the definitions of those terms themselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It can be a challenge to write good alt text.

I read it through and understood the difference without looking at the image. 👍

:align: center

FreeTypeFont.getmask2 fill parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Binary file added docs/example/size_vs_bbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions docs/releasenotes/9.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Previous code::

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width, height = draw.textsize("Hello world")
width, height = draw.textsize("Hello world", font)

width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld", font)

Use instead::

Expand All @@ -84,11 +84,19 @@ Use instead::

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width = draw.textlength("Hello world")
width = draw.textlength("Hello world", font)

left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld")
left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld", font)
width, height = right - left, bottom - top

Previously, the ``size`` methods returned a ``height`` that included the vertical
offset of the text, while the new ``bbox`` methods distinguish this as a ``top``
offset.

.. image:: ./example/size_vs_bbox.png
radarhere marked this conversation as resolved.
Show resolved Hide resolved
:alt: Demonstration of size height vs bbox top and bottom
:align: center

API Additions
=============

Expand Down
Loading