Recently it took me to create a picture on the fly. Decided to use library for python PIL. It supports a bunch of formats, as well as a variety of color systems (RGB, RGBA and more simple). So, consider the simplest how to create a picture and draw something on it.
To begin with, we will connect the necessary modules.
from PIL import Image, ImageDraw
The Image module directly controls the source of the image, allows you to create, save, open a picture. And ImageDraw, is responsible directly for drawing geometric objects.
Now create a new drawing:
')
image = Image.new("RGBA", (320,320), (0,0,0,0))
Here, the first parameter is the type of picture, it can be: 1 (black and white), L (monochrome, grayscale), RGB, RGBA (RGB with alpha channel), CMYK, YCbCr, I (32 bit Integer pixels), F ( 32 bit Float pixels).
The second parameter is an object of type tuple that specifies the size of the image.
The third parameter is the color itself, since we have RGBA, the record (0,0,0,0) corresponds to full transparency.
After that, to draw something on it, you need to create an ImageDraw object and pass it our drawing:
draw = ImageDraw.Draw(image)
Let's try to draw a red ellipse:
draw. ellipse((10,10,300,300), fill="red", outline="red")
Here we draw an ellipse, with starting coordinates: 10.10, and ending: 300,300. Also, the fill parameter sets the fill color, and outline the outline color. In addition to code names, you can use an HTML entry, or RGB (A) as a tuple element.
From the shapes available for drawing: curve, line, text, cut out ellipse, point, polygon.
After that, remove the draw and save the picture:
del draw
image.save("/path/to/save/test.png", "PNG")
After that we get a .png file with a red circle on a transparent background:

Here, I think for the initial understanding will help someone.
Found a brief
documentation of official documentation. (uploaded to your site)
Official
website with documentation