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
1111Example
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+
3057Methods
3158-------
3259
0 commit comments