2013-10-12 11:52:01 +04:00
|
|
|
|
.. py:module:: PIL.ImageDraw
|
|
|
|
|
.. py:currentmodule:: PIL.ImageDraw
|
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
|
:py:mod:`~PIL.ImageDraw` Module
|
|
|
|
|
===============================
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
|
The :py:mod:`~PIL.ImageDraw` module provides simple 2D graphics for
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:py:class:`~PIL.Image.Image` objects. You can use this module to create new
|
|
|
|
|
images, annotate or retouch existing images, and to generate graphics on the
|
|
|
|
|
fly for web use.
|
|
|
|
|
|
|
|
|
|
For a more advanced drawing library for PIL, see the `aggdraw module`_.
|
|
|
|
|
|
2017-10-23 18:45:57 +03:00
|
|
|
|
.. _aggdraw module: https://github.com/pytroll/aggdraw
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Example: Draw a gray cross over an image
|
|
|
|
|
----------------------------------------
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2013-10-13 00:53:31 +04:00
|
|
|
|
from PIL import Image, ImageDraw
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-02-29 02:29:44 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-02-29 02:29:44 +03:00
|
|
|
|
draw = ImageDraw.Draw(im)
|
|
|
|
|
draw.line((0, 0) + im.size, fill=128)
|
|
|
|
|
draw.line((0, im.size[1], im.size[0], 0), fill=128)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-02-29 02:29:44 +03:00
|
|
|
|
# write to stdout
|
|
|
|
|
im.save(sys.stdout, "PNG")
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Concepts
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
Coordinates
|
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
The graphics interface uses the same coordinate system as PIL itself, with (0,
|
2019-01-27 14:10:54 +03:00
|
|
|
|
0) in the upper left corner. Any pixels drawn outside of the image bounds will
|
|
|
|
|
be discarded.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Colors
|
|
|
|
|
^^^^^^
|
|
|
|
|
|
|
|
|
|
To specify colors, you can use numbers or tuples just as you would use with
|
2018-02-14 12:09:00 +03:00
|
|
|
|
:py:meth:`PIL.Image.new` or :py:meth:`PIL.Image.Image.putpixel`. For “1”,
|
2013-10-12 11:52:01 +04:00
|
|
|
|
“L”, and “I” images, use integers. For “RGB” images, use a 3-tuple containing
|
|
|
|
|
integer values. For “F” images, use integer or floating point values.
|
|
|
|
|
|
|
|
|
|
For palette images (mode “P”), use integers as color indexes. In 1.1.4 and
|
|
|
|
|
later, you can also use RGB 3-tuples or color names (see below). The drawing
|
|
|
|
|
layer will automatically assign color indexes, as long as you don’t draw with
|
|
|
|
|
more than 256 colors.
|
|
|
|
|
|
|
|
|
|
Color Names
|
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
See :ref:`color-names` for the color names supported by Pillow.
|
|
|
|
|
|
|
|
|
|
Fonts
|
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
|
|
PIL can use bitmap fonts or OpenType/TrueType fonts.
|
|
|
|
|
|
|
|
|
|
Bitmap fonts are stored in PIL’s own format, where each font typically consists
|
2017-06-21 07:44:06 +03:00
|
|
|
|
of two files, one named .pil and the other usually named .pbm. The former
|
2013-10-12 11:52:01 +04:00
|
|
|
|
contains font metrics, the latter raster data.
|
|
|
|
|
|
|
|
|
|
To load a bitmap font, use the load functions in the :py:mod:`~PIL.ImageFont`
|
|
|
|
|
module.
|
|
|
|
|
|
|
|
|
|
To load a OpenType/TrueType font, use the truetype function in the
|
|
|
|
|
:py:mod:`~PIL.ImageFont` module. Note that this function depends on third-party
|
|
|
|
|
libraries, and may not available in all PIL builds.
|
|
|
|
|
|
2014-07-23 03:43:08 +04:00
|
|
|
|
Example: Draw Partial Opacity Text
|
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
# get an image
|
2020-06-01 10:16:30 +03:00
|
|
|
|
base = Image.open("Pillow/Tests/images/hopper.png").convert("RGBA")
|
2014-07-23 03:43:08 +04:00
|
|
|
|
|
|
|
|
|
# make a blank image for the text, initialized to transparent text color
|
2020-06-01 10:16:30 +03:00
|
|
|
|
txt = Image.new("RGBA", base.size, (255,255,255,0))
|
2014-07-23 03:43:08 +04:00
|
|
|
|
|
|
|
|
|
# get a font
|
2020-06-01 10:16:30 +03:00
|
|
|
|
fnt = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 40)
|
2014-07-23 03:43:08 +04:00
|
|
|
|
# get a drawing context
|
2015-10-11 13:24:35 +03:00
|
|
|
|
d = ImageDraw.Draw(txt)
|
2014-07-23 03:43:08 +04:00
|
|
|
|
|
|
|
|
|
# draw text, half opacity
|
|
|
|
|
d.text((10,10), "Hello", font=fnt, fill=(255,255,255,128))
|
|
|
|
|
# draw text, full opacity
|
|
|
|
|
d.text((10,60), "World", font=fnt, fill=(255,255,255,255))
|
|
|
|
|
|
|
|
|
|
out = Image.alpha_composite(base, txt)
|
|
|
|
|
|
|
|
|
|
out.show()
|
|
|
|
|
|
2020-04-12 08:11:29 +03:00
|
|
|
|
Example: Draw Multiline Text
|
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
|
|
|
|
# create an image
|
|
|
|
|
out = Image.new("RGB", (150, 100), (255, 255, 255))
|
|
|
|
|
|
|
|
|
|
# get a font
|
|
|
|
|
fnt = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 40)
|
|
|
|
|
# get a drawing context
|
|
|
|
|
d = ImageDraw.Draw(out)
|
|
|
|
|
|
|
|
|
|
# draw multiline text
|
|
|
|
|
d.multiline_text((10,10), "Hello\nWorld", font=fnt, fill=(0, 0, 0))
|
|
|
|
|
|
|
|
|
|
out.show()
|
2014-07-23 03:43:08 +04:00
|
|
|
|
|
|
|
|
|
|
2013-10-12 11:52:01 +04:00
|
|
|
|
Functions
|
|
|
|
|
---------
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: Draw(im, mode=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Creates an object that can be used to draw in the given image.
|
|
|
|
|
|
|
|
|
|
Note that the image will be modified in place.
|
|
|
|
|
|
2014-07-23 03:43:08 +04:00
|
|
|
|
:param im: The image to draw in.
|
|
|
|
|
:param mode: Optional mode to use for color values. For RGB
|
|
|
|
|
images, this argument can be RGB or RGBA (to blend the
|
|
|
|
|
drawing into the image). For all other modes, this argument
|
|
|
|
|
must be the same as the image mode. If omitted, the mode
|
|
|
|
|
defaults to the mode of the image.
|
|
|
|
|
|
2013-10-12 11:52:01 +04:00
|
|
|
|
Methods
|
|
|
|
|
-------
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.getfont()
|
2017-07-16 08:22:46 +03:00
|
|
|
|
|
|
|
|
|
Get the current default font.
|
|
|
|
|
|
|
|
|
|
:returns: An image font.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.arc(xy, start, end, fill=None, width=0)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws an arc (a portion of a circle outline) between the start and end
|
|
|
|
|
angles, inside the given bounding box.
|
|
|
|
|
|
2019-07-07 03:12:09 +03:00
|
|
|
|
:param xy: Two points to define the bounding box. Sequence of ``[(x0, y0),
|
|
|
|
|
(x1, y1)]`` or ``[x0, y0, x1, y1]``, where ``x1 >= x0`` and ``y1 >=
|
|
|
|
|
y0``.
|
|
|
|
|
:param start: Starting angle, in degrees. Angles are measured from 3
|
|
|
|
|
o'clock, increasing clockwise.
|
2014-05-28 00:55:43 +04:00
|
|
|
|
:param end: Ending angle, in degrees.
|
2014-05-20 23:59:31 +04:00
|
|
|
|
:param fill: Color to use for the arc.
|
2018-04-13 08:37:54 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
|
|
|
|
|
2018-09-16 23:41:24 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.bitmap(xy, bitmap, fill=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws a bitmap (mask) at the given position, using the current fill color
|
|
|
|
|
for the non-zero portions. The bitmap should be a valid transparency mask
|
|
|
|
|
(mode “1”) or matte (mode “L” or “RGBA”).
|
|
|
|
|
|
|
|
|
|
This is equivalent to doing ``image.paste(xy, color, bitmap)``.
|
|
|
|
|
|
|
|
|
|
To paste pixel data into an image, use the
|
|
|
|
|
:py:meth:`~PIL.Image.Image.paste` method on the image itself.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.chord(xy, start, end, fill=None, outline=None, width=1)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2017-07-16 08:21:26 +03:00
|
|
|
|
Same as :py:meth:`~PIL.ImageDraw.ImageDraw.arc`, but connects the end points
|
2013-10-12 11:52:01 +04:00
|
|
|
|
with a straight line.
|
|
|
|
|
|
2019-07-07 03:12:09 +03:00
|
|
|
|
:param xy: Two points to define the bounding box. Sequence of ``[(x0, y0),
|
|
|
|
|
(x1, y1)]`` or ``[x0, y0, x1, y1]``, where ``x1 >= x0`` and ``y1 >=
|
|
|
|
|
y0``.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:param outline: Color to use for the outline.
|
|
|
|
|
:param fill: Color to use for the fill.
|
2018-04-13 08:37:54 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2018-09-16 23:41:24 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.ellipse(xy, fill=None, outline=None, width=1)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws an ellipse inside the given bounding box.
|
|
|
|
|
|
2017-11-15 13:25:03 +03:00
|
|
|
|
:param xy: Two points to define the bounding box. Sequence of either
|
2019-07-07 03:12:09 +03:00
|
|
|
|
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``, where ``x1 >= x0``
|
|
|
|
|
and ``y1 >= y0``.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:param outline: Color to use for the outline.
|
|
|
|
|
:param fill: Color to use for the fill.
|
2018-04-13 08:37:54 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
|
|
|
|
|
2018-09-16 23:41:24 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.line(xy, fill=None, width=0, joint=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
Draws a line between the coordinates in the ``xy`` list.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
:param xy: Sequence of either 2-tuples like ``[(x, y), (x, y), ...]`` or
|
|
|
|
|
numeric values like ``[x, y, x, y, ...]``.
|
|
|
|
|
:param fill: Color to use for the line.
|
2018-09-16 14:29:09 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.5
|
|
|
|
|
|
|
|
|
|
.. note:: This option was broken until version 1.1.6.
|
2020-06-08 06:17:08 +03:00
|
|
|
|
:param joint: Joint type between a sequence of lines. It can be ``"curve"``, for rounded edges, or ``None``.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2018-09-16 15:30:11 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=1)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Same as arc, but also draws straight lines between the end points and the
|
|
|
|
|
center of the bounding box.
|
|
|
|
|
|
2019-07-07 03:12:09 +03:00
|
|
|
|
:param xy: Two points to define the bounding box. Sequence of ``[(x0, y0),
|
|
|
|
|
(x1, y1)]`` or ``[x0, y0, x1, y1]``, where ``x1 >= x0`` and ``y1 >=
|
|
|
|
|
y0``.
|
|
|
|
|
:param start: Starting angle, in degrees. Angles are measured from 3
|
|
|
|
|
o'clock, increasing clockwise.
|
2015-03-24 07:16:53 +03:00
|
|
|
|
:param end: Ending angle, in degrees.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:param fill: Color to use for the fill.
|
2015-03-24 07:16:53 +03:00
|
|
|
|
:param outline: Color to use for the outline.
|
2018-09-01 14:40:36 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
2018-04-13 08:37:54 +03:00
|
|
|
|
|
2018-09-16 23:41:24 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.point(xy, fill=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws points (individual pixels) at the given coordinates.
|
|
|
|
|
|
|
|
|
|
:param xy: Sequence of either 2-tuples like ``[(x, y), (x, y), ...]`` or
|
|
|
|
|
numeric values like ``[x, y, x, y, ...]``.
|
|
|
|
|
:param fill: Color to use for the point.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.polygon(xy, fill=None, outline=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws a polygon.
|
|
|
|
|
|
|
|
|
|
The polygon outline consists of straight lines between the given
|
|
|
|
|
coordinates, plus a straight line between the last and the first
|
|
|
|
|
coordinate.
|
|
|
|
|
|
|
|
|
|
:param xy: Sequence of either 2-tuples like ``[(x, y), (x, y), ...]`` or
|
|
|
|
|
numeric values like ``[x, y, x, y, ...]``.
|
|
|
|
|
:param outline: Color to use for the outline.
|
|
|
|
|
:param fill: Color to use for the fill.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws a rectangle.
|
|
|
|
|
|
2017-11-15 13:25:03 +03:00
|
|
|
|
:param xy: Two points to define the bounding box. Sequence of either
|
2013-10-12 11:52:01 +04:00
|
|
|
|
``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. The second point
|
|
|
|
|
is just outside the drawn rectangle.
|
|
|
|
|
:param outline: Color to use for the outline.
|
|
|
|
|
:param fill: Color to use for the fill.
|
2018-04-12 18:15:27 +03:00
|
|
|
|
:param width: The line width, in pixels.
|
|
|
|
|
|
2018-09-16 23:41:24 +03:00
|
|
|
|
.. versionadded:: 5.3.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.shape(shape, fill=None, outline=None)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
.. warning:: This method is experimental.
|
|
|
|
|
|
|
|
|
|
Draw a shape.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. 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)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Draws the string at the given position.
|
|
|
|
|
|
|
|
|
|
:param xy: Top left corner of the text.
|
2015-06-18 06:22:04 +03:00
|
|
|
|
:param text: Text to be drawn. If it contains any newline characters,
|
2020-06-02 21:48:53 +03:00
|
|
|
|
the text is passed on to
|
2020-06-02 22:14:36 +03:00
|
|
|
|
:py:meth:`~PIL.ImageDraw.ImageDraw.multiline_text`.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:param fill: Color to use for the text.
|
2015-07-15 14:00:47 +03:00
|
|
|
|
:param font: An :py:class:`~PIL.ImageFont.ImageFont` instance.
|
2020-06-02 21:48:53 +03:00
|
|
|
|
:param spacing: If the text is passed on to
|
|
|
|
|
:py:meth:`~PIL.ImageDraw.ImageDraw.multiline_text`,
|
2016-02-01 01:22:18 +03:00
|
|
|
|
the number of pixels between lines.
|
2020-06-02 21:48:53 +03:00
|
|
|
|
:param align: If the text is passed on to
|
|
|
|
|
:py:meth:`~PIL.ImageDraw.ImageDraw.multiline_text`,
|
2020-06-04 11:43:24 +03:00
|
|
|
|
``"left"``, ``"center"`` or ``"right"``.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
:param direction: Direction of the text. It can be ``"rtl"`` (right to
|
|
|
|
|
left), ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).
|
2018-09-18 13:41:55 +03:00
|
|
|
|
Requires libraqm.
|
2015-07-15 14:00:47 +03:00
|
|
|
|
|
2017-06-29 17:02:02 +03:00
|
|
|
|
.. versionadded:: 4.2.0
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
2017-06-29 17:02:02 +03:00
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
|
font features that are not enabled by default,
|
2020-06-01 10:16:30 +03:00
|
|
|
|
for example ``"dlig"`` or ``"ss01"``, but can be also
|
|
|
|
|
used to turn off default font features, for
|
|
|
|
|
example ``"-liga"`` to disable ligatures or ``"-kern"``
|
2017-06-29 17:02:02 +03:00
|
|
|
|
to disable kerning. To get all supported
|
2020-06-02 21:28:34 +03:00
|
|
|
|
features, see `OpenType docs`_.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
2015-07-15 14:00:47 +03:00
|
|
|
|
|
2019-04-23 23:19:17 +03:00
|
|
|
|
:param language: Language of the text. Different languages may use
|
2019-03-07 01:07:30 +03:00
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
|
correct substitutions as appropriate, if available.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
It should be a `BCP 47 language code`_.
|
2019-03-07 01:07:30 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
|
|
|
|
|
:param stroke_fill: Color to use for the text stroke. If not given, will default to
|
2020-06-02 22:14:36 +03:00
|
|
|
|
the ``fill`` parameter.
|
2019-07-28 23:40:03 +03:00
|
|
|
|
|
2020-06-02 22:14:36 +03:00
|
|
|
|
.. versionadded:: 6.2.0
|
2019-07-28 23:40:03 +03:00
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None)
|
2015-06-18 06:22:04 +03:00
|
|
|
|
|
|
|
|
|
Draws the string at the given position.
|
|
|
|
|
|
|
|
|
|
:param xy: Top left corner of the text.
|
2015-07-15 15:43:52 +03:00
|
|
|
|
:param text: Text to be drawn.
|
2015-07-15 14:00:47 +03:00
|
|
|
|
:param fill: Color to use for the text.
|
2015-06-18 06:22:04 +03:00
|
|
|
|
:param font: An :py:class:`~PIL.ImageFont.ImageFont` instance.
|
|
|
|
|
:param spacing: The number of pixels between lines.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
:param align: ``"left"``, ``"center"`` or ``"right"``.
|
|
|
|
|
:param direction: Direction of the text. It can be ``"rtl"`` (right to
|
|
|
|
|
left), ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).
|
2018-09-18 13:41:55 +03:00
|
|
|
|
Requires libraqm.
|
2015-06-18 06:22:04 +03:00
|
|
|
|
|
2017-06-29 17:02:02 +03:00
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
|
font features that are not enabled by default,
|
2020-06-01 10:16:30 +03:00
|
|
|
|
for example ``"dlig"`` or ``"ss01"``, but can be also
|
|
|
|
|
used to turn off default font features, for
|
|
|
|
|
example ``"-liga"`` to disable ligatures or ``"-kern"``
|
2017-06-29 17:02:02 +03:00
|
|
|
|
to disable kerning. To get all supported
|
2020-06-02 21:28:34 +03:00
|
|
|
|
features, see `OpenType docs`_.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
2015-06-18 06:22:04 +03:00
|
|
|
|
|
2019-04-23 23:19:17 +03:00
|
|
|
|
:param language: Language of the text. Different languages may use
|
2019-03-12 06:21:52 +03:00
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
|
correct substitutions as appropriate, if available.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
It should be a `BCP 47 language code`_.
|
2019-03-12 06:21:52 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)
|
2013-10-12 11:52:01 +04:00
|
|
|
|
|
|
|
|
|
Return the size of the given string, in pixels.
|
|
|
|
|
|
2015-06-18 06:22:04 +03:00
|
|
|
|
:param text: Text to be measured. If it contains any newline characters,
|
2020-06-03 11:23:24 +03:00
|
|
|
|
the text is passed on to :py:meth:`~PIL.ImageDraw.ImageDraw.multiline_textsize`.
|
2015-06-18 06:22:04 +03:00
|
|
|
|
:param font: An :py:class:`~PIL.ImageFont.ImageFont` instance.
|
2020-06-02 21:48:53 +03:00
|
|
|
|
:param spacing: If the text is passed on to
|
|
|
|
|
:py:meth:`~PIL.ImageDraw.ImageDraw.multiline_textsize`,
|
2016-02-01 01:22:18 +03:00
|
|
|
|
the number of pixels between lines.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
:param direction: Direction of the text. It can be ``"rtl"`` (right to
|
|
|
|
|
left), ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).
|
2018-09-18 13:41:55 +03:00
|
|
|
|
Requires libraqm.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
|
font features that are not enabled by default,
|
2020-06-01 10:16:30 +03:00
|
|
|
|
for example ``"dlig"`` or ``"ss01"``, but can be also
|
|
|
|
|
used to turn off default font features, for
|
|
|
|
|
example ``"-liga"`` to disable ligatures or ``"-kern"``
|
2017-06-29 17:02:02 +03:00
|
|
|
|
to disable kerning. To get all supported
|
2020-06-02 21:28:34 +03:00
|
|
|
|
features, see `OpenType docs`_.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
2019-04-23 23:19:17 +03:00
|
|
|
|
:param language: Language of the text. Different languages may use
|
2019-03-06 14:01:25 +03:00
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
|
correct substitutions as appropriate, if available.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
It should be a `BCP 47 language code`_.
|
2019-03-06 14:01:25 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
2017-06-29 17:02:02 +03:00
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)
|
2015-06-18 06:22:04 +03:00
|
|
|
|
|
|
|
|
|
Return the size of the given string, in pixels.
|
|
|
|
|
|
2015-07-15 15:43:52 +03:00
|
|
|
|
:param text: Text to be measured.
|
2013-10-12 11:52:01 +04:00
|
|
|
|
:param font: An :py:class:`~PIL.ImageFont.ImageFont` instance.
|
2015-06-18 06:22:04 +03:00
|
|
|
|
:param spacing: The number of pixels between lines.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
:param direction: Direction of the text. It can be ``"rtl"`` (right to
|
|
|
|
|
left), ``"ltr"`` (left to right) or ``"ttb"`` (top to bottom).
|
2018-09-18 13:41:55 +03:00
|
|
|
|
Requires libraqm.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
|
font features that are not enabled by default,
|
2020-06-01 10:16:30 +03:00
|
|
|
|
for example ``"dlig"`` or ``"ss01"``, but can be also
|
|
|
|
|
used to turn off default font features, for
|
|
|
|
|
example ``"-liga"`` to disable ligatures or ``"-kern"``
|
2017-06-29 17:02:02 +03:00
|
|
|
|
to disable kerning. To get all supported
|
2020-06-02 21:28:34 +03:00
|
|
|
|
features, see `OpenType docs`_.
|
2017-06-29 17:02:02 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
2017-07-16 08:22:46 +03:00
|
|
|
|
|
2019-04-23 23:19:17 +03:00
|
|
|
|
:param language: Language of the text. Different languages may use
|
2019-03-12 06:21:52 +03:00
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
|
correct substitutions as appropriate, if available.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
It should be a `BCP 47 language code`_.
|
2019-03-12 06:21:52 +03:00
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: getdraw(im=None, hints=None)
|
2017-07-16 08:22:46 +03:00
|
|
|
|
|
|
|
|
|
.. warning:: This method is experimental.
|
|
|
|
|
|
|
|
|
|
A more advanced 2D drawing interface for PIL images,
|
|
|
|
|
based on the WCK interface.
|
|
|
|
|
|
|
|
|
|
:param im: The image to draw in.
|
|
|
|
|
:param hints: An optional list of hints.
|
|
|
|
|
:returns: A (drawing context, drawing resource factory) tuple.
|
|
|
|
|
|
2020-06-14 15:39:48 +03:00
|
|
|
|
.. py:method:: floodfill(image, xy, value, border=None, thresh=0)
|
2017-07-16 08:22:46 +03:00
|
|
|
|
|
|
|
|
|
.. warning:: This method is experimental.
|
|
|
|
|
|
|
|
|
|
Fills a bounded region with a given color.
|
|
|
|
|
|
|
|
|
|
:param image: Target image.
|
|
|
|
|
:param xy: Seed position (a 2-item coordinate tuple).
|
|
|
|
|
:param value: Fill color.
|
|
|
|
|
:param border: Optional border value. If given, the region consists of
|
|
|
|
|
pixels with a color different from the border color. If not given,
|
|
|
|
|
the region consists of pixels having the same color as the seed
|
|
|
|
|
pixel.
|
|
|
|
|
:param thresh: Optional threshold value which specifies a maximum
|
|
|
|
|
tolerable difference of a pixel value from the 'background' in
|
|
|
|
|
order for it to be replaced. Useful for filling regions of non-
|
|
|
|
|
homogeneous, but similar, colors.
|
2020-06-01 10:16:30 +03:00
|
|
|
|
|
|
|
|
|
.. _BCP 47 language code: https://www.w3.org/International/articles/language-tags/
|
2020-06-02 21:28:34 +03:00
|
|
|
|
.. _OpenType docs: https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|