mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 20:43:43 +03:00
Show how to use anchors to align text in imagefont deprecations
This commit is contained in:
parent
55d0289a7d
commit
7490aee836
|
@ -260,6 +260,30 @@ offset.
|
||||||
:alt: Demonstration of size height vs bbox top and bottom
|
:alt: Demonstration of size height vs bbox top and bottom
|
||||||
:align: center
|
: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
|
FreeTypeFont.getmask2 fill parameter
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,30 @@ offset.
|
||||||
:alt: Demonstration of size height vs bbox top and bottom
|
:alt: Demonstration of size height vs bbox top and bottom
|
||||||
:align: center
|
: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
|
API Additions
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user