The line() method draws a line from the upper left to lower right corners of bounding box xy and canvas. Some of the common shapes we can draw using ‘ImageDraw’ module are as follows − Lineįollowing is, the syntax to draw a line using python pillow − ImageDraw module allows us to create different shapes by first creating a drawing object with the image you want to work with and then apply it. Output Drawing Shapes using ‘ImageDraw’ module # make a blank image for the text, initialized to transparent text color #Import required modules from Pillow packageįrom PIL import Image, ImageDraw, ImageFontīase = Image.open('images/boy.jpg').convert('RGBA') The background of the canvas is the "img" image.įollowing python example draws text on the given image −
ImageDraw.Draw(img) returns a drawable canvas representation of Image parameter img. If you save the above program as Example.py and execute, it draws a line across the image and displays it using standard PNG display utility, as follows − CanvasĪn ImageDraw is a Pillow drawable surface (i.e., a canvas) of an Image. įor some drawing commands, we require angle values.įollowing python example draws a line across the given image −ĭraw.line((0, im.size, im.size, 0), fill=128) Most of the drawing commands may require a bounding box parameter that specifies the area on the image to which the command is to be applied.Ī sequence of co-ordinates can be represented as. The color RGB representation and support is provided by the module ImageColor.īitmap, OpenType or TrueType are the acceptable fonts for text annotations. The origin of the two-dimensional co-ordinate system used by ImageDraw, is in the upper left corner of the image. A pixel is the smallest dot of color being supported. The graphics commands support the drawing of shapes and annotation of text.Īn image can be well-thought-out to be a two-dimensional array of pixels (picture elements). Generally, we use this module to create new images, annotate or retouch existing images and to generate graphics on the fly for web use. The ‘ImageDraw’ module provides simple 2D graphics support for Image Object.