mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #23 from nulano/imagefont
Show how to use anchors to align text in ImageFont deprecations
This commit is contained in:
commit
83433d89a1
|
@ -260,6 +260,30 @@ offset.
|
|||
: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
|
||||
|
||||
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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -97,6 +97,30 @@ offset.
|
|||
: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
|
||||
|
||||
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
|
||||
=============
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user