When you need to draw on an image, import the
ImageDraw module like this:
Then instantiate a
draw = ImageDraw.Draw(
Image object you want to draw on.
Methods on a
Draw object include:
Draws an arc, that part of the ellipse fitting inside
the bounding box
and lying between angles
Note: Angles increase clockwise,
unlike angles elsewhere in the PIL. For example,
draw.arc((0,0,200,200), 0, 135) would
draw a circular arc centered at (100,100) and
extending from the east to the southwest.
If supplied, the
argument specifies the
color of the arc. The default color is white.
Same as the
.arc() method, but it also
draws a straight line connecting the endpoints of the
For this method, the
argument determines the
color inside, that is, between the chord and the arc.
The default is that this area is not filled.
To change the color of the perimeter border around
the chord's area, set the
argument to the color
you want. The default color is white.
Draws the ellipse that fits inside the bounding box
. To draw a circle, use
a square bounding box.
Note that the ellipse will include the left and top
sides of the bounding box, but they will
exclude the right and bottom
sides of the box. For example, a bounding box
(0,0,10,10) will give you a circle of
diameter 10, not diameter 11.
If you omit the
argument, only the
perimeter of the ellipse is drawn. If you pass a
color to this argument, the interior of the ellipse
will be filled with that color.
to draw the
perimeter border using color
. The default color is
Draws one or more line segments. The argument
endpoints, and can have either of these forms:
A sequence of 2-element sequences, each of which
specifies one endpoint. For example,
draw.line([(10,20),(100,20)] would draw
a straight line from (10,20) to (100,20). You
can specify any number of points to get a
“polyline;” for example,
draw.line(((60,60), (90,60), (90,90), (60,90),
(60,60))) would draw a square 30 pixels
on a side.
A sequence containing an even number of values.
Each succeeding pair is taken as an
(x,y) coordinate. For example,
give you the same result as the first example in
the paragraph above.
Similar to the
.arc() method, but
draws two radii connecting the endpoints of the arc
to the center. The
arguments work in the
same way as in the
determines the interior color, and
the color of the border.
Sets the pixel at coordinates
color specified by the
argument. The default
color is white.
Works like the
.line() method, but
after drawing all the specified line segments, it
draws one more that connects the last point back to
the first. The interior displays the
transparent by default. The border is drawn in the
color, defaulting to white.
(90,90), (60,90)], fill="red", outline="green") would draw a square box with a green outline,
filled with red.
Draws the text of the string
on the image with its
upper left corner at coordinates
To write the text in color, pass that color to the
argument; the default text color is white.
There is a default font, rather small (about 11
pixels tall) and in a serif style. You can also
specify a font using the
argument; see the
module for more information on fonts.
For a given text string
, returns a tuple
is the width in pixels that
text will occupy on the display, and
height in pixels.
argument is omitted, you will get the size using
the default font. Supply a font to this method's
argument to get the size of the text in that