From d3b974b78607d36fbfa392b80c81adbd08d277ac Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 17 Feb 2024 11:19:32 +1100 Subject: [PATCH 1/6] Use font in ImageDraw examples --- docs/deprecations.rst | 8 ++++---- docs/releasenotes/9.2.0.rst | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 205fcb9abcd..a58ce9bcba6 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -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:: @@ -247,9 +247,9 @@ 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 FreeTypeFont.getmask2 fill parameter diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index b875edf8e5c..3b8d2535f74 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -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:: @@ -84,9 +84,9 @@ 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 API Additions From 617b9cbc00759f042d2c38ea63a14adca2bc902b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 17 Feb 2024 11:50:48 +1100 Subject: [PATCH 2/6] Describe difference between size and bbox --- docs/deprecations.rst | 4 ++++ docs/releasenotes/9.2.0.rst | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index a58ce9bcba6..c90ad481adb 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -252,6 +252,10 @@ Use instead:: 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 explicitly distinguish this as a +``top`` offset. + FreeTypeFont.getmask2 fill parameter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index 3b8d2535f74..495926ca749 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -89,6 +89,10 @@ Use instead:: 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 explicitly distinguish this as a +``top`` offset. + API Additions ============= From 55d0289a7dd5f5261e89b9084fbeac681bf2d626 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 19 Feb 2024 17:08:21 +1100 Subject: [PATCH 3/6] Added image to illustrate size vs bbox --- docs/deprecations.rst | 8 ++++++-- docs/example/size_vs_bbox.png | Bin 0 -> 12934 bytes docs/releasenotes/9.2.0.rst | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 docs/example/size_vs_bbox.png diff --git a/docs/deprecations.rst b/docs/deprecations.rst index c90ad481adb..74021a218ef 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -253,8 +253,12 @@ Use instead:: 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 explicitly distinguish this as a -``top`` offset. +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 + :align: center FreeTypeFont.getmask2 fill parameter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/example/size_vs_bbox.png b/docs/example/size_vs_bbox.png new file mode 100644 index 0000000000000000000000000000000000000000..11a05d2a8146a612741c7e4ec4d3cf0ce05a35a0 GIT binary patch literal 12934 zcmb8WWmsEH7cPtwJh($BPH`&~4^W_Jad&qq?hxEvi?w)hcP&n#xNC8Dhm$_<_xHQ5 zbN*zq*UT)RnS0GnB9s)QFi=TQVPIe|WTYjOVPIgHq2Gr9aL~`y4q0f!DK8@-rs@HE z{0-5ObZ>efiIaw&ZnBm!e}UV@)loZ1 zwukSQyYYAaqi=>ffs-H1;zGdWbZCb!o3}BU-0uFNgNg^f<#DO4CL7PPE z|F!=fiT`iNttQZU3~3xr@Z}8Vvt~cbgE0n8mDN>xYE?A-kZcHSYLs61fe?gEqCg;F zM;4-vNZN_^fb;aCmZom5>fvptF<%eaMEh@5WK0Y3xY&$gtU!n(yX$AsxK z!_7_)!W$Yfz|p=HW0~ywCI{&Ssb1$qNx1z9&gfrdGXl1wa)*ksDtQ@3w9%i@jQBhC z?jJ_+osC*l*VZSsLj(zMme`I?4$jI_@d#&%)FaVapFZNti2+~ffeI}l{5htLQVUyW z3lr1n7jlgb zJu#T5c)XEsJf`2Z|D|lwTpfcnHmyDF62HYaTtb?n+u_5nb15XyirA23Zcq8$JqbC6_Cc<_+Pp4i4oYuA*m>dTVlHJZ%dM5F%2g;Y93SZ_(;+h0GxF8=ic*fk>BT98B4b!J~|e z<5lE^5v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d?5|F2=5NP_TSbIk zuBe*G(e+e}7~Z#LbC~jT2IGEJnS&}!$4Pv|xK5Iy(r`*TjXOU{h#$k@x_4jF9|odn z7dTR=mQSCZlz;EEAXBBf*gYf2-Y$G*P5#bx+fR%PGla1OkDke{i!C%oO^1-%jPr5X zeO^yiUzN=xxUHXXe{Ob*CCz5Qp6utcL>rL|BoxnU1|!GGM*;&pjPdHgPXExOSyRj1om0?yqo+9QLvfd0L zOh>V9&G|nK>43T1r8Aksaznz3yf{D+=GEHmr9pHddF-h?ALZXASQBD zE-sLyWfYRZVlxCGgxqbT$J-MJoUiY^Ig8CNV|^%SSPRd8fBXp1nLUv-y;YlkTSnvS z$?k1C7MhZH&C?+c(lp1Mzx=a{{&xv;Hm&Jzb=>6a4nf##`La%=)TFq^{q3>uSSmG8 zZrM}xZXNU-cYBZy{nH2%?Bruw4u>EFGr30yL?sQ72H?Qq1VI8IASw_QGm3zz)Zh8JTGS literal 0 HcmV?d00001 diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index 495926ca749..db514068f77 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -90,8 +90,12 @@ Use instead:: 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 explicitly distinguish this as a -``top`` offset. +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 + :align: center API Additions ============= From 7490aee8362c589a475035bf86c05b29c894593c Mon Sep 17 00:00:00 2001 From: Nulano Date: Mon, 19 Feb 2024 20:18:18 +0100 Subject: [PATCH 4/6] Show how to use anchors to align text in imagefont deprecations --- docs/deprecations.rst | 24 ++++++++++++++++++++++++ docs/releasenotes/9.2.0.rst | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 74021a218ef..9efb1316d5c 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -260,6 +260,30 @@ offset. :alt: Demonstration of size height vs bbox top and bottom :align: center +If you are using these methods for aligning text, consider using :ref:`text-anchors` instead +which avoid issues that can occur with non-English text or unusual fonts. +For example, instead of the following code:: + + from PIL import Image, ImageDraw, ImageFont + + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf") + + im = Image.new("RGB", (100, 100)) + draw = ImageDraw.Draw(im) + width, height = draw.textsize("Hello world", font) + x, y = (100 - width) / 2, (100 - height) / 2 + draw.text((x, y), "Hello world", font=font) + +Use instead:: + + from PIL import Image, ImageDraw, ImageFont + + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf") + + im = Image.new("RGB", (100, 100)) + draw = ImageDraw.Draw(im) + draw.text((100 / 2, 100 / 2), "Hello world", font=font, anchor="mm") + FreeTypeFont.getmask2 fill parameter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index db514068f77..e8bf33b60f2 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -97,6 +97,30 @@ offset. :alt: Demonstration of size height vs bbox top and bottom :align: center +If you are using these methods for aligning text, consider using :ref:`text-anchors` instead +which avoid issues that can occur with non-English text or unusual fonts. +For example, instead of the following code:: + + from PIL import Image, ImageDraw, ImageFont + + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf") + + im = Image.new("RGB", (100, 100)) + draw = ImageDraw.Draw(im) + width, height = draw.textsize("Hello world", font) + x, y = (100 - width) / 2, (100 - height) / 2 + draw.text((x, y), "Hello world", font=font) + +Use instead:: + + from PIL import Image, ImageDraw, ImageFont + + font = ImageFont.truetype("Tests/fonts/FreeMono.ttf") + + im = Image.new("RGB", (100, 100)) + draw = ImageDraw.Draw(im) + draw.text((100 / 2, 100 / 2), "Hello world", font=font, anchor="mm") + API Additions ============= From 64579510c018440edb1b0c9c67f36d478f969f38 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 20 Feb 2024 21:37:06 +1100 Subject: [PATCH 5/6] Updated alt text --- docs/deprecations.rst | 2 +- docs/releasenotes/9.2.0.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 74021a218ef..9fd64fdaa42 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -257,7 +257,7 @@ 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 + :alt: 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. :align: center FreeTypeFont.getmask2 fill parameter diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index db514068f77..b596a6ab20f 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -94,7 +94,7 @@ 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 + :alt: 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. :align: center API Additions From 56a02b76eb403356436e6480c5ada23930825e36 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Tue, 20 Feb 2024 21:37:40 +1100 Subject: [PATCH 6/6] Corrected image path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ondrej Baranovič --- docs/releasenotes/9.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/releasenotes/9.2.0.rst b/docs/releasenotes/9.2.0.rst index b596a6ab20f..677438bc63e 100644 --- a/docs/releasenotes/9.2.0.rst +++ b/docs/releasenotes/9.2.0.rst @@ -93,7 +93,7 @@ Previously, the ``size`` methods returned a ``height`` that included the vertica offset of the text, while the new ``bbox`` methods distinguish this as a ``top`` offset. -.. image:: ./example/size_vs_bbox.png +.. image:: ../example/size_vs_bbox.png :alt: 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. :align: center