January 2020
Intermediate to advanced
346 pages
9h 8m
English
To draw an image from scratch, we can use Pillow's Image and ImageDraw classes, as follows:
image = Image.new('RGB', (width, height))draw = ImageDraw.Draw(image, 'RGBA')
'RGB' and 'RGBA' are the values for the mode argument. The 'RGB' value indicates three 8-bit values per pixel – one for each of the colors Red ('R'), Green ('G'), and Blue ('B'). The 'RGBA' value adds a fourth 8-bit value, "A", representing the alpha (opacity) level of the drawings to be added. The combination of an RGB base image and an RGBA drawing will allow us to draw polygons of varying degrees of transparency on top of a black background.
Now, we can add a polygon to the base image by using the ImageDraw class' polygon function, as shown ...
Read now
Unlock full access