Skip to content

Commit

Permalink
Added examples for updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 3, 2022
1 parent 4783ecf commit 406e9a2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,40 @@ Deprecated Use
:py:meth:`.ImageDraw2.Draw.textsize` :py:meth:`.ImageDraw2.Draw.textbbox` and :py:meth:`.ImageDraw2.Draw.textlength`
=========================================================================== =============================================================================================================

Previous code:

.. code-block:: python
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
width, height = font.getsize("Hello world")
left, top = font.getoffset("Hello world")
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width, height = draw.textsize("Hello world")
width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")
Use instead:

.. code-block:: python
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
left, top, right, bottom = font.getbbox("Hello world")
width, height = right - left, bottom - top
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width = draw.textlength("Hello world")
left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld")
width, height = right - left, bottom - top
Removed features
----------------

Expand Down
4 changes: 4 additions & 0 deletions docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ Methods
.. py:method:: ImageDraw.textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.

Use :py:meth:`textlength()` to measure the offset of following text with
1/64 pixel precision.
Expand Down Expand Up @@ -494,6 +496,8 @@ Methods
.. py:method:: ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.

Use :py:meth:`.multiline_textbbox` instead.

Expand Down
34 changes: 34 additions & 0 deletions docs/releasenotes/9.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ Deprecated Use
:py:meth:`.ImageDraw2.Draw.textsize` :py:meth:`.ImageDraw2.Draw.textbbox` and :py:meth:`.ImageDraw2.Draw.textlength`
=========================================================================== =============================================================================================================

Previous code:

.. code-block:: python
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
width, height = font.getsize("Hello world")
left, top = font.getoffset("Hello world")
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width, height = draw.textsize("Hello world")
width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")
Use instead:

.. code-block:: python
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
left, top, right, bottom = font.getbbox("Hello world")
width, height = right - left, bottom - top
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width = draw.textlength("Hello world")
left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld")
width, height = right - left, bottom - top
API Additions
=============

Expand Down
10 changes: 10 additions & 0 deletions src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def _load_pilfont_data(self, file, image):
def getsize(self, text, *args, **kwargs):
"""
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
Expand Down Expand Up @@ -427,6 +429,8 @@ def getsize(
):
"""
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.
Use :py:meth:`getlength()` to measure the offset of following text with
1/64 pixel precision.
Expand Down Expand Up @@ -497,6 +501,8 @@ def getsize_multiline(
):
"""
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.
Use :py:meth:`.ImageDraw.multiline_textbbox` instead.
Expand Down Expand Up @@ -556,6 +562,8 @@ def getsize_multiline(
def getoffset(self, text):
"""
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.
Use :py:meth:`.getbbox` instead.
Expand Down Expand Up @@ -850,6 +858,8 @@ def __init__(self, font, orientation=None):
def getsize(self, text, *args, **kwargs):
"""
.. deprecated:: 9.2.0
See https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
for more information.
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
"""
Expand Down

0 comments on commit 406e9a2

Please sign in to comment.