Skip to content

Commit c2d5088

Browse files
committed
Added documentation
1 parent 0da7ad7 commit c2d5088

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

docs/reference/ImageDraw.rst

+35-5
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Methods
351351

352352
Draw a shape.
353353

354-
.. py:method:: ImageDraw.text(xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False)
354+
.. py:method:: ImageDraw.text(xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False, font_size=None)
355355
356356
Draws the string at the given position.
357357

@@ -416,8 +416,14 @@ Methods
416416

417417
.. versionadded:: 8.0.0
418418

419+
:param font_size: If ``font`` is not provided, then the size to use for the default
420+
font.
421+
Keyword-only argument.
419422

420-
.. py:method:: ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False)
423+
.. versionadded:: 10.1.0
424+
425+
426+
.. py:method:: ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False, font_size=None)
421427
422428
Draws the string at the given position.
423429

@@ -477,7 +483,13 @@ Methods
477483

478484
.. versionadded:: 8.0.0
479485

480-
.. py:method:: ImageDraw.textlength(text, font=None, direction=None, features=None, language=None, embedded_color=False)
486+
:param font_size: If ``font`` is not provided, then the size to use for the default
487+
font.
488+
Keyword-only argument.
489+
490+
.. versionadded:: 10.1.0
491+
492+
.. py:method:: ImageDraw.textlength(text, font=None, direction=None, features=None, language=None, embedded_color=False, font_size=None)
481493
482494
Returns length (in pixels with 1/64 precision) of given text when rendered
483495
in font with provided direction, features, and language.
@@ -538,9 +550,15 @@ Methods
538550
It should be a `BCP 47 language code`_.
539551
Requires libraqm.
540552
:param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
553+
:param font_size: If ``font`` is not provided, then the size to use for the default
554+
font.
555+
Keyword-only argument.
556+
557+
.. versionadded:: 10.1.0
558+
541559
:return: Either width for horizontal text, or height for vertical text.
542560

543-
.. py:method:: ImageDraw.textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False)
561+
.. py:method:: ImageDraw.textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False, font_size=None)
544562
545563
Returns bounding box (in pixels) of given text relative to given anchor
546564
when rendered in font with provided direction, features, and language.
@@ -588,9 +606,15 @@ Methods
588606
Requires libraqm.
589607
:param stroke_width: The width of the text stroke.
590608
:param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
609+
:param font_size: If ``font`` is not provided, then the size to use for the default
610+
font.
611+
Keyword-only argument.
612+
613+
.. versionadded:: 10.1.0
614+
591615
:return: ``(left, top, right, bottom)`` bounding box
592616

593-
.. py:method:: ImageDraw.multiline_textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False)
617+
.. py:method:: ImageDraw.multiline_textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False, font_size=None)
594618
595619
Returns bounding box (in pixels) of given text relative to given anchor
596620
when rendered in font with provided direction, features, and language.
@@ -632,6 +656,12 @@ Methods
632656
Requires libraqm.
633657
:param stroke_width: The width of the text stroke.
634658
:param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
659+
:param font_size: If ``font`` is not provided, then the size to use for the default
660+
font.
661+
Keyword-only argument.
662+
663+
.. versionadded:: 10.1.0
664+
635665
:return: ``(left, top, right, bottom)`` bounding box
636666

637667
.. py:method:: getdraw(im=None, hints=None)

docs/releasenotes/10.1.0.rst

+27-9
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ to be specified, rather than a single number for both dimensions. ::
4141
API Additions
4242
=============
4343

44-
ImageOps.cover
45-
^^^^^^^^^^^^^^
46-
47-
Returns a resized version of the image, so that the requested size is covered,
48-
while maintaining the original aspect ratio.
49-
50-
See :ref:`relative-resize` for a comparison between this and similar ``ImageOps``
51-
methods.
52-
5344
EpsImagePlugin.gs_binary
5445
^^^^^^^^^^^^^^^^^^^^^^^^
5546

@@ -69,6 +60,33 @@ channel, a palette with an alpha channel, or a "transparency" key in the
6960
Even if this attribute is true, the image might still appear solid, if all of
7061
the values shown within are opaque.
7162

63+
ImageOps.cover
64+
^^^^^^^^^^^^^^
65+
66+
Returns a resized version of the image, so that the requested size is covered,
67+
while maintaining the original aspect ratio.
68+
69+
See :ref:`relative-resize` for a comparison between this and similar ``ImageOps``
70+
methods.
71+
72+
size and font_size arguments when using default font
73+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
75+
Pillow has had a "better than nothing" default font, which can only be drawn at
76+
one font size. Now, if FreeType support is available, a version of
77+
`Aileron Regular <https://dotcolon.net/font/aileron>`_ is loaded, which can be
78+
drawn at chosen font sizes.
79+
80+
The following ``size`` and ``font_size`` arguments can now be used to specify a
81+
font size for this new builtin font::
82+
83+
ImageFont.load_default(size=24)
84+
draw.text((0, 0), "test", font_size=24)
85+
draw.textlength((0, 0), "test", font_size=24)
86+
draw.textbbox((0, 0), "test", font_size=24)
87+
draw.multiline_text((0, 0), "test", font_size=24)
88+
draw.multiline_textbbox((0, 0), "test", font_size=24)
89+
7290
Other Changes
7391
=============
7492

src/PIL/ImageFont.py

+4
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,10 @@ def load_default(size=None):
869869
870870
.. versionadded:: 1.1.4
871871
872+
:param size: The font size of Aileron Regular.
873+
874+
.. versionadded:: 10.1.0
875+
872876
:return: A font object.
873877
"""
874878
if core.__class__.__name__ == "module" or size is not None:

0 commit comments

Comments
 (0)