Skip to content

Commit d5e1601

Browse files
committed
Improved documentation
1 parent e533ccc commit d5e1601

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

docs/reference/ImageDraw.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ Methods
582582
hello_world = hello + world # kerning is disabled, no need to adjust
583583
assert hello_world == draw.textlength("HelloWorld", font, features=["-kern"]) # True
584584

585+
.. seealso:: :py:meth:`PIL.ImageText.Text.get_length`
586+
585587
.. versionadded:: 8.0.0
586588

587589
:param text: Text to be measured. May not contain any newline characters.
@@ -683,6 +685,8 @@ Methods
683685
1/64 pixel precision. The bounding box includes extra margins for
684686
some fonts, e.g. italics or accents.
685687

688+
.. seealso:: :py:meth:`PIL.ImageText.Text.get_bbox`
689+
686690
.. versionadded:: 8.0.0
687691

688692
:param xy: The anchor coordinates of the text.

docs/reference/ImageText.rst

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
:py:mod:`~PIL.ImageText` module
55
===============================
66

7-
The :py:mod:`~PIL.ImageText` module defines a class with the same name. Instances of
8-
this class provide a way to use fonts with text strings or bytes. The result is a
9-
simple API to apply styling to pieces of text and measure or draw them.
7+
The :py:mod:`~PIL.ImageText` module defines a :py:class:`~PIL.ImageText.Text` class.
8+
Instances of this class provide a way to use fonts with text strings or bytes. The
9+
result is a simple API to apply styling to pieces of text and measure or draw them.
1010

1111
Example
1212
-------
@@ -27,6 +27,33 @@ Example
2727
d = ImageDraw.Draw(im)
2828
d.text((0, 0), text, "#f00")
2929

30+
Comparison
31+
----------
32+
33+
Without ``ImageText.Text``::
34+
35+
from PIL import Image, ImageDraw
36+
im = Image.new(mode, size)
37+
d = ImageDraw.Draw(im)
38+
39+
d.textlength(text, font, direction, features, language, embedded_color)
40+
d.multiline_textbbox(xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color)
41+
d.text(xy, text, fill, font, anchor, spacing, align, direction, features, language, stroke_width, stroke_fill, embedded_color)
42+
43+
With ``ImageText.Text``::
44+
45+
from PIL import ImageText
46+
text = ImageText.Text(text, font, mode, spacing, direction, features, language)
47+
text.embed_color()
48+
text.stroke(stroke_width, stroke_fill)
49+
50+
text.get_length()
51+
text.get_bbox(xy, anchor, align)
52+
53+
im = Image.new(mode, size)
54+
d = ImageDraw.Draw(im)
55+
d.text(xy, text, fill, anchor=anchor, align=align)
56+
3057
Methods
3158
-------
3259

docs/releasenotes/12.0.0.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,39 @@ Image.alpha_composite: LA images
124124

125125
:py:meth:`~PIL.Image.alpha_composite` can now use LA images as well as RGBA.
126126

127+
API additions
128+
=============
129+
130+
Added ImageText.Text
131+
^^^^^^^^^^^^^^^^^^^^
132+
133+
:py:class:`PIL.ImageText.Text` has been added, as a simpler way to use fonts with text
134+
strings or bytes.
135+
136+
Without ``ImageText.Text``::
137+
138+
from PIL import Image, ImageDraw
139+
im = Image.new(mode, size)
140+
d = ImageDraw.Draw(im)
141+
142+
d.textlength(text, font, direction, features, language, embedded_color)
143+
d.multiline_textbbox(xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color)
144+
d.text(xy, text, fill, font, anchor, spacing, align, direction, features, language, stroke_width, stroke_fill, embedded_color)
145+
146+
With ``ImageText.Text``::
147+
148+
from PIL import ImageText
149+
text = ImageText.Text(text, font, mode, spacing, direction, features, language)
150+
text.embed_color()
151+
text.stroke(stroke_width, stroke_fill)
152+
153+
text.get_length()
154+
text.get_bbox(xy, anchor, align)
155+
156+
im = Image.new(mode, size)
157+
d = ImageDraw.Draw(im)
158+
d.text(xy, text, fill, anchor=anchor, align=align)
159+
127160
Other changes
128161
=============
129162

0 commit comments

Comments
 (0)