The Python Imaging Library | ![]() |
|
Copyright © 1997 by Fredrik Lundh <fredrik@pythonware.com> | ||
Updated 17 Aug 1997 |
< The ImageChops Module | The ImageDraw Class | The ImageEnhance Module >
This class provide some basic graphics support for "1", "L" and "P" images.
To use the ImageDraw class, import the ImageDraw module.
import Image, ImageDraw im = Image.open("lena.gif") # draw a grey cross over the image draw = ImageDraw.ImageDraw(im) draw.setink(128) draw.line((0, 0), im.size) draw.line((0, im.size[1]), (im.size[0], 0)) del draw im.show()
ImageDraw( image ) creates an object that can be used to draw in the given image. The image must be a "1", "L" or "P" image. Ink is set to 255, and fill is off.
line( from, to ) draws a line between the two points.
line( list ) connects the points in the list. The list can be any sequence object containing either 2-tuples [(x, y), ...] or numeric values [x, y, ...].
point( position ) draws a point at the given position.
polygon( list ) draws a polygon. The list can be any sequence object containing either 2-tuples [(x, y), ...] or numeric values [x, y, ...].
rectangle( box ) draws a rectangle. Note that the second coordinate pair defines a point just outside the rectangle, also when the rectangle is not filled.
setink( ink ) selects the pixel value to use with subsequent operations.
setfill( onoff ) selects if subsequently polygons and rectangles should be filled objects or just outlined.
< The ImageChops Module | The ImageDraw Class | The ImageEnhance Module >