ImageDraw
from blanket import ImageDraw exposes a Pillow-shaped drawing context.
ImageDraw.Draw(image, mode=None, antialias=False) constructs an in-place drawing context.
It supports point, line, rectangle, rounded_rectangle, ellipse,
arc, chord, pieslice, polygon, and regular_polygon. Closed shapes
accept a fill, outline, and outline width; lines and arcs accept a fill and
stroke width. Coordinates are truncated to integers and clipped to the image.
Rectangle bounds include both endpoints. Colors accept names, integers, and
channel tuples. Use mode="RGBA" on an RGB image to blend translucent inks;
drawing on an RGBA image replaces pixels, including alpha.
Coordinate arguments also accept ImagePath.Path objects. Color strings use the ImageColor parser, including modern CSS4 color forms.
Indexed modes require numeric ink values; palette color allocation is not implemented. Integer and float modes accept numeric inks. Multichannel 16-bit images require an explicit conversion to 8-bit before drawing. As in Pillow, 16-bit points write in native byte order, while rectangles respect the mode's byte order. Wide outlines follow Pillow's behavior, including overlap and extension outside degenerate rectangle bounds.
Set antialias=True for 4 by 4 supersampled geometric coverage. This requires
8-bit non-indexed images; bilevel, indexed, integer, and float images use
ordinary drawing. point still paints individual pixels. Polygon fills use
the even-odd rule. Lines use rounded stroke joins and caps. Ellipse outlines
extend inward; other path outlines are centered on their edges. Curved edges
and wide strokes can differ from Pillow's rasterization.
textlength, textbbox, and multiline_textbbox measure text; text and
multiline_text draw it. The built-in fallback is a fixed-width 5 by 7 bitmap
font, scaled by font_size to whole pixel multiples. Lowercase uses uppercase
glyphs; unsupported characters use ?. Its metrics and appearance differ
from Pillow's default font. Set draw.font or pass font= to use a font
object providing getlength, getbbox, and getmask2 (or getmask). A Pillow
font can be supplied explicitly without making Pillow a runtime dependency.
Text supports anchors, strokes, line spacing, and left/center/right alignment.
Antialiased font masks require the same 8-bit modes as geometric coverage;
set draw.fontmode = "1" for binary font masks. Use
ImageFont to load TrueType/OpenType and legacy PIL bitmap fonts,
or access the built-in fallback explicitly. Outline fonts support Unicode
shaping, bidirectional layout, and basic vertical text. Vertical multiline text
and embedded-color fonts are unsupported.
floodfill(image, xy, value, border=None, thresh=0) fills four-connected pixels.
Without a border it compares pixels to the seed, using the sum of absolute
channel differences (or scalar sample differences) and the threshold. With a
border it fills until it reaches the border or the fill color. Seeds outside
the image are ignored. Fill inks follow the drawing context's mode rules.
from blanket import Image, ImageDraw
image = Image.new("RGB", (8, 8), (40, 100, 180))
draw = ImageDraw.Draw(image)
draw.rectangle((1, 1, 6, 6), fill="white", outline="black", width=2)
draw.point([(2, 2), (5, 5)], fill="red")
image = Image.new("RGB", (120, 60), "white")
draw = ImageDraw.Draw(image, antialias=True)
draw.rounded_rectangle((2, 2, 117, 57), radius=8, outline="blue", width=2)
draw.text((12, 20), "Blanket", fill="black", font_size=14)
Reference
Draw
Create a drawing context for im.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im
|
Image
|
Image to draw on. |
required |
mode
|
str | None
|
Optional ink mode. Defaults to the image mode. |
None
|
antialias
|
bool
|
Use supersampled coverage for geometric edges on 8-bit images. |
False
|
Returns:
| Type | Description |
|---|---|
ImageDraw
|
A context that modifies |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (8, 8), (40, 100, 180))
draw = ImageDraw.Draw(image)
ImageDraw
ImageDraw(im: Image, mode: str | None = None, *, antialias: bool = False)
In-place drawing context for a Blanket image.
Drawing changes the supplied image directly. Coordinates use an origin at the top-left corner; fractional values are truncated toward zero. Pixels outside the image are ignored, including negative coordinates.
Inks accept color names, packed integers, or channel tuples in the drawing mode. Indexed images require numeric indices rather than palette color allocation. Integer and float images accept numeric sample values. Multichannel 16-bit images must be converted to 8-bit before drawing.
An RGBA context on an RGB image blends ink alpha into existing pixels.
Geometric drawing on an RGBA image replaces all channels, including alpha.
Text masks apply coverage to existing pixels. Set antialias=True for
supersampled geometric edges on 8-bit non-indexed images. Curved edges
and wide strokes can differ from Pillow's rasterization.
Attributes:
| Name | Type | Description |
|---|---|---|
im |
Image modified by this context. |
|
mode |
Mode used to interpret ink values. |
|
blend |
Whether RGBA inks blend onto an RGB image. |
|
antialias |
Whether geometric edges use supersampled coverage. |
|
font |
Default font object for text, or |
|
fontmode |
Font mask mode, initially |
Configure a drawing context for im.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im
|
Image
|
Image to draw on. Pixels are modified in place. |
required |
mode
|
str | None
|
Color mode for ink values. Defaults to the image mode. Use |
None
|
antialias
|
bool
|
Use supersampled coverage for geometric edges. |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the image is closed or the drawing mode does not
match the image mode, except for |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (8, 8), (40, 100, 180))
draw = ImageDraw.Draw(image)
print(draw.mode)
arc
arc(xy: Coords, start: float, end: float, fill: Color = None, width: int = 1) -> None
Draw the curved edge of an ellipse between two angles.
Angles run clockwise from the positive x-axis. A sweep of at least 360 degrees draws a full arc; equal angles draw nothing. Negative sweeps wrap clockwise through zero. The arc has no radial edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Ellipse bounds as |
required |
start
|
float
|
Starting angle in degrees; must be finite. |
required |
end
|
float
|
Ending angle in degrees; must be finite. |
required |
fill
|
Color
|
Stroke ink. |
None
|
width
|
int
|
Stroke thickness in pixels. Nonpositive values draw nothing. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, ink, or width have incompatible types. |
ValueError
|
If bounds or angles are invalid, the image is closed, or the ink, sample depth, or anti-aliasing mode is unsupported. |
chord
chord(xy: Coords, start: float, end: float, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw an elliptical segment closed by a straight chord.
The fill is drawn before the outline. The outline includes both the curved edge and the straight line joining its endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Ordered ellipse bounds as four values or two coordinate pairs. |
required |
start
|
float
|
Starting angle in degrees, clockwise from the positive x-axis. Must be finite. |
required |
end
|
float
|
Ending angle in degrees. Negative sweeps wrap clockwise; sweeps of at least 360 degrees cover the full ellipse. |
required |
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or width have incompatible types. |
ValueError
|
If bounds or angles are invalid, the image is closed, or the ink, sample depth, or anti-aliasing mode is unsupported. |
ellipse
ellipse(xy: Coords, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw an ellipse inside an inclusive bounding box.
The fill is drawn first. The outline extends inward and is skipped
when it equals the fill. If both inks are None, nothing is drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Ordered bounds as |
required |
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or width have incompatible types. |
ValueError
|
If bounds are malformed or reversed, the image is closed, or the ink, sample depth, or anti-aliasing mode is unsupported. |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (32, 24), "white")
ImageDraw.Draw(image).ellipse((2, 2, 29, 21), fill="blue", outline="black", width=2)
line
line(xy: Coords, fill: Color = None, width: int = 0, joint: str | None = None) -> None
Draw connected line segments through a sequence of coordinates.
Pixels outside the image are ignored. A one-coordinate sequence draws
a point; an empty sequence draws nothing. Wide strokes use rounded
caps and joins for both supported joint values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Flat coordinate values or a sequence of |
required |
fill
|
Color
|
Stroke ink. |
None
|
width
|
int
|
Stroke thickness in pixels. Values at or below one use a one-pixel stroke. |
0
|
joint
|
str | None
|
|
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, ink, or width have incompatible types. |
ValueError
|
If coordinates are malformed, |
pieslice
pieslice(xy: Coords, start: float, end: float, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw an elliptical sector bounded by an arc and two radii.
The fill is drawn before the outline, which includes the radial edges. Equal angles draw nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Ordered ellipse bounds as four values or two coordinate pairs. |
required |
start
|
float
|
Starting angle in degrees, clockwise from the positive x-axis. Must be finite. |
required |
end
|
float
|
Ending angle in degrees. Negative sweeps wrap clockwise; sweeps of at least 360 degrees cover the full ellipse. |
required |
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or width have incompatible types. |
ValueError
|
If bounds or angles are invalid, the image is closed, or the ink, sample depth, or anti-aliasing mode is unsupported. |
point
point(xy: Coords, fill: Color = None) -> None
Draw one or more points in place.
Coordinates outside the image are ignored. Repeated coordinates draw repeatedly, including repeated alpha blending in an RGBA context on an RGB image. An empty coordinate sequence draws nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
A single |
required |
fill
|
Color
|
Ink color or sample value. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates or the ink have an incompatible type. |
ValueError
|
If coordinates are malformed, the image is closed, the ink is invalid, or the sample depth is unsupported. |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (8, 8), "white")
draw = ImageDraw.Draw(image)
draw.point((2, 3), fill="red")
draw.point([(1, 1), (6, 6)], fill=(0, 0, 255))
Notes
For Pillow compatibility, points on 16-bit integer images write samples in native byte order, even in explicit-endian modes.
polygon
polygon(xy: Coords, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw a closed polygon using the even-odd fill rule.
The last vertex connects to the first automatically. The fill is drawn before the outline; path outlines are centered on the edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Flat coordinate values or at least two |
required |
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or width have incompatible types. |
ValueError
|
If fewer than two vertices are supplied, coordinates are malformed, the image is closed, or the ink, sample depth, or anti-aliasing mode is unsupported. |
regular_polygon
regular_polygon(bounding_circle: tuple[float, float, float] | tuple[tuple[float, float], float], n_sides: int, rotation: float = 0, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw a regular polygon inscribed in a bounding circle.
Vertices are rounded to two decimal places before their coordinates are truncated for polygon drawing. Rotation increases counterclockwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounding_circle
|
tuple[float, float, float] | tuple[tuple[float, float], float]
|
Center and radius as |
required |
n_sides
|
int
|
Integer number of sides, at least three. |
required |
rotation
|
float
|
Counterclockwise rotation in degrees. Zero places the first vertex at the bottom-left of the polygon. |
0
|
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the circle, side count, inks, or width have incompatible types. |
ValueError
|
If the circle, rotation, or side count is invalid, the image is closed, or drawing in the image mode is unsupported. |
rectangle
rectangle(xy: Coords, fill: Color = None, outline: Color = None, width: int = 1) -> None
Draw a rectangle with optional fill and outline in place.
Both bounding endpoints are included. The fill is drawn first and
the outline afterward. Pixels outside the image are ignored. If both
colors are None, nothing is drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Bounds as |
required |
fill
|
Color
|
Interior ink color or sample value. |
None
|
outline
|
Color
|
Border ink color or sample value. |
None
|
width
|
int
|
Outline thickness in pixels. Values at or below zero skip the outline. |
1
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or |
ValueError
|
If bounds are malformed or reversed, the image is closed, an ink is invalid, or the sample depth is unsupported. |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (16, 16), "white")
draw = ImageDraw.Draw(image)
draw.rectangle((2, 2, 13, 13), fill="blue", outline="black", width=2)
ImageDraw.Draw(image, "RGBA").rectangle((4, 4, 11, 11), fill=(255, 0, 0, 128))
Notes
Outlines normally extend inward. Wide outlines and degenerate bounds follow Pillow's overlapping edge behavior and may extend beyond the bounds. Rectangles on 16-bit integer images respect the mode's byte order.
rounded_rectangle
rounded_rectangle(xy: Coords, radius: float = 0, fill: Color = None, outline: Color = None, width: int = 1, corners: tuple[bool, bool, bool, bool] | None = None) -> None
Draw a rectangle with individually selectable rounded corners.
The radius is clamped to half the smaller bounding dimension. The fill is drawn before the centered path outline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
Coords
|
Ordered bounds as four values or two coordinate pairs. Fractional coordinates are truncated toward zero. |
required |
radius
|
float
|
Corner radius in pixels; must be finite and nonnegative. |
0
|
fill
|
Color
|
Interior ink, or |
None
|
outline
|
Color
|
Border ink, or |
None
|
width
|
int
|
Border thickness in pixels. Nonpositive values skip it. |
1
|
corners
|
tuple[bool, bool, bool, bool] | None
|
Four flags in top-left, top-right, bottom-right,
bottom-left order. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, radius, inks, or width have incompatible types. |
ValueError
|
If bounds, radius, or corner flags are invalid, the image is closed, or drawing in the image mode is unsupported. |
text
text(xy: tuple[float, float], text: str, fill: Color = None, font: object | None = None, anchor: str | None = None, spacing: float = 4, align: str = 'left', direction: str | None = None, features: Sequence[str] | None = None, language: str | None = None, stroke_width: float = 0, stroke_fill: Color = None, embedded_color: bool = False, font_size: float | None = None) -> None
Draw text using the bitmap fallback or a supplied font object.
Strings containing newlines are passed to :meth:multiline_text.
Use ImageFont.truetype to load TrueType and OpenType fonts.
Font objects must provide getlength, getbbox, and getmask2 or
getmask. Coverage masks require 8-bit non-indexed images; use
fontmode="1" for binary masks on other supported drawing modes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
tuple[float, float]
|
Text anchor position in image coordinates. |
required |
text
|
str
|
String to draw. |
required |
fill
|
Color
|
Text ink. |
None
|
font
|
object | None
|
Explicit font object. Otherwise use |
None
|
anchor
|
str | None
|
Two-character font anchor, such as |
None
|
spacing
|
float
|
Additional pixels between lines when text contains newlines. |
4
|
align
|
str
|
Multiline alignment: |
'left'
|
direction
|
str | None
|
Text direction passed to the font when specified. |
None
|
features
|
Sequence[str] | None
|
OpenType feature names passed to the font when specified. |
None
|
language
|
str | None
|
Language tag passed to the font when specified. |
None
|
stroke_width
|
float
|
Finite, nonnegative stroke thickness, rounded up to a whole pixel for rendering. |
0
|
stroke_fill
|
Color
|
Stroke ink. |
None
|
embedded_color
|
bool
|
Embedded-color font request. Currently unsupported. |
False
|
font_size
|
float | None
|
Requested bitmap fallback height. Defaults to seven pixels and scales in whole multiples of seven. Ignored when an explicit or context font is used. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If coordinates, inks, or the font interface are incompatible. |
ValueError
|
If stroke width, font size, or anchor is invalid, the image is closed, or mask coverage is unsupported for its mode. |
NotImplementedError
|
If |
Notes
The bitmap fallback uses uppercase glyphs for lowercase letters
and ? for unsupported characters. It ignores font shaping options.
Its appearance and metrics differ from Pillow's default font.
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (120, 40), "white")
draw = ImageDraw.Draw(image)
draw.text((8, 8), "Blanket", fill="blue", font_size=14)
multiline_text
multiline_text(xy: tuple[float, float], text: str, fill: Color = None, font: object | None = None, anchor: str | None = None, spacing: float = 4, align: str = 'left', direction: str | None = None, features: Sequence[str] | None = None, language: str | None = None, stroke_width: float = 0, stroke_fill: Color = None, embedded_color: bool = False, font_size: float | None = None) -> None
Draw newline-separated text with spacing and alignment.
Each line uses the selected font's advance length for alignment.
Line spacing includes the font's `A` bounding height and stroke width.
Args:
xy: Position of the multiline text anchor.
text: String whose lines are separated by `
.
fill: Text ink.Noneuses the context's default ink.
font: Explicit font object; otherwise useself.fontor the
built-in bitmap fallback.
anchor: Two-character anchor. Horizontal codes arel,m, andr; vertical codes area,m,s, andd. Defaults to"la".
spacing: Finite additional spacing between lines in pixels.
align: Line alignment:"left","center", or"right".
direction: Direction passed to the font. Vertical"ttb"layout
is unsupported for multiline text.
features: OpenType feature names passed to the font when specified.
language: Language tag passed to the font when specified.
stroke_width: Finite, nonnegative stroke thickness, rounded up
to a whole pixel for rendering.
stroke_fill: Stroke ink.None` uses the text ink.
embedded_color: Embedded-color font request. Currently unsupported.
font_size: Bitmap fallback height, scaled in multiples of seven
pixels. Ignored when an explicit or context font is used.
Raises:
TypeError: If arguments or the font interface are incompatible.
ValueError: If alignment, anchor, spacing, stroke width, or direction
is invalid, or drawing in the image mode is unsupported.
NotImplementedError: If `embedded_color` is true.
textlength
textlength(text: str, font: object | None = None, direction: str | None = None, features: Sequence[str] | None = None, language: str | None = None, embedded_color: bool = False, font_size: float | None = None) -> float
Return the single-line advance length in pixels.
Font kerning is included when provided by the font. The advance describes the next text position; glyph bounds may extend beyond it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Single-line string to measure. Newlines are unsupported. |
required |
font
|
object | None
|
Explicit font object; otherwise use |
None
|
direction
|
str | None
|
Direction passed to the font when specified. |
None
|
features
|
Sequence[str] | None
|
OpenType feature names passed to the font when specified. |
None
|
language
|
str | None
|
Language tag passed to the font when specified. |
None
|
embedded_color
|
bool
|
Embedded-color font request. Currently unsupported. |
False
|
font_size
|
float | None
|
Bitmap fallback height, scaled in multiples of seven pixels. Ignored when an explicit or context font is used. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The font's advance length as a float, without stroke expansion. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the text or font interface is incompatible. |
ValueError
|
If text contains newlines or the fallback size is invalid. |
NotImplementedError
|
If |
textbbox
textbbox(xy: tuple[float, float], text: str, font: object | None = None, anchor: str | None = None, spacing: float = 4, align: str = 'left', direction: str | None = None, features: Sequence[str] | None = None, language: str | None = None, stroke_width: float = 0, embedded_color: bool = False, font_size: float | None = None) -> tuple[float, float, float, float]
Return text bounds at xy, including the anchor and stroke.
Strings containing newlines are measured with
:meth:multiline_textbbox. Measurement does not modify the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xy
|
tuple[float, float]
|
Text anchor position in image coordinates. |
required |
text
|
str
|
String to measure. |
required |
font
|
object | None
|
Explicit font object; otherwise use |
None
|
anchor
|
str | None
|
Font anchor, such as |
None
|
spacing
|
float
|
Additional spacing in pixels for newline-separated text. |
4
|
align
|
str
|
Multiline alignment: |
'left'
|
direction
|
str | None
|
Direction passed to the font when specified. |
None
|
features
|
Sequence[str] | None
|
OpenType feature names passed to the font when specified. |
None
|
language
|
str | None
|
Language tag passed to the font when specified. |
None
|
stroke_width
|
float
|
Finite, nonnegative expansion passed to the font's bounding-box calculation. |
0
|
embedded_color
|
bool
|
Embedded-color font request. Currently unsupported. |
False
|
font_size
|
float | None
|
Bitmap fallback height, scaled in multiples of seven pixels. Ignored when an explicit or context font is used. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
|
float
|
include font margins and are not clipped to the image. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments or the font interface are incompatible. |
ValueError
|
If stroke width, font size, anchor, or multiline layout options are invalid. |
NotImplementedError
|
If |
multiline_textbbox
multiline_textbbox(xy: tuple[float, float], text: str, font: object | None = None, anchor: str | None = None, spacing: float = 4, align: str = 'left', direction: str | None = None, features: Sequence[str] | None = None, language: str | None = None, stroke_width: float = 0, embedded_color: bool = False, font_size: float | None = None) -> tuple[float, float, float, float]
Return the union of the bounds of newline-separated text.
Uses the same line positions as :meth:`multiline_text` and does not
modify the image. Font margins and stroke expansion are included.
Args:
xy: Position of the multiline text anchor.
text: String whose lines are separated by `
.
font: Explicit font object; otherwise useself.fontor the
built-in bitmap fallback.
anchor: Two-character anchor using horizontall,m, orrand verticala,m,s, ord. Defaults to"la".
spacing: Finite additional spacing between lines in pixels.
align: Line alignment:"left","center", or"right".
direction: Direction passed to the font. Vertical"ttb"` layout
is unsupported for multiline text.
features: OpenType feature names passed to the font when specified.
language: Language tag passed to the font when specified.
stroke_width: Finite, nonnegative expansion passed to the font's
bounding-box calculation.
embedded_color: Embedded-color font request. Currently unsupported.
font_size: Bitmap fallback height, scaled in multiples of seven
pixels. Ignored when an explicit or context font is used.
Returns:
`(left, top, right, bottom)` in image coordinates, without
clipping to the image.
Raises:
TypeError: If arguments or the font interface are incompatible.
ValueError: If alignment, anchor, spacing, stroke width, direction,
or fallback size is invalid.
NotImplementedError: If `embedded_color` is true.
floodfill
floodfill(image: Image, xy: tuple[float, float], value: Color, border: Color = None, thresh: float = 0) -> None
Fill four-connected pixels starting at xy.
The fill is applied in place. Seeds outside the image are ignored. Without a border, pixels are compared to the seed using the sum of absolute channel differences, or the absolute scalar sample difference. With a border, filling stops at pixels equal to the border or fill ink.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
Image to fill. |
required |
xy
|
tuple[float, float]
|
Seed coordinate. Fractional values are truncated toward zero. |
required |
value
|
Color
|
Fill ink in the image mode, following the drawing context's color and numeric sample rules. |
required |
border
|
Color
|
Optional ink that bounds the fill. |
None
|
thresh
|
float
|
Finite, nonnegative maximum difference from the seed. With a border, neighbor selection uses exact ink equality instead. |
0
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the image, coordinates, or inks have incompatible types. |
ValueError
|
If the threshold is invalid, the image is closed, or the ink or sample depth is unsupported. |
Examples:
from blanket import Image, ImageDraw
image = Image.new("RGB", (8, 8), (40, 100, 180))
ImageDraw.floodfill(image, (0, 0), (255, 0, 0))