diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 9be92770ab9..92f116846f7 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -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 ---------------- diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index e19e87a0d52..623f601efeb 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -443,6 +443,9 @@ Methods .. 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. Use :py:meth:`textbbox()` to get the exact bounding box based on an anchor. @@ -495,6 +498,9 @@ Methods .. 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. Return the size of the given string, in pixels. diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index 9c102f1776a..6dbfa2702eb 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -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 ============= diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 9386d008602..3d1e4b0bfe1 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -139,6 +139,9 @@ def getsize(self, text, *args, **kwargs): """ .. deprecated:: 9.2.0 + For more information, see + https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#deprecations. + Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead. Returns width and height (in pixels) of given text. @@ -428,6 +431,9 @@ def getsize( """ .. deprecated:: 9.2.0 + For more information, see + https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#deprecations. + Use :py:meth:`getlength()` to measure the offset of following text with 1/64 pixel precision. Use :py:meth:`getbbox()` to get the exact bounding box based on an anchor. @@ -498,6 +504,9 @@ def getsize_multiline( """ .. deprecated:: 9.2.0 + For more information, see + https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#deprecations. + Use :py:meth:`.ImageDraw.multiline_textbbox` instead. Returns width and height (in pixels) of given text if rendered in font @@ -557,6 +566,9 @@ def getoffset(self, text): """ .. deprecated:: 9.2.0 + For more information, see + https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#deprecations. + Use :py:meth:`.getbbox` instead. Returns the offset of given text. This is the gap between the @@ -851,6 +863,9 @@ def getsize(self, text, *args, **kwargs): """ .. deprecated:: 9.2.0 + For more information, see + https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#deprecations. + Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead. """ deprecate("getsize", 10, "getbbox or getlength")