12.6.2.1 determine standard colors by RGB code; 12.6.2.2 use commands of module Image in PIL library (load, create, size, save) to manipulate images; PIL library The PIL (Python image library), or rather its Pillow modification, is used to work with images. To install the library, you need to run the pip install <Module name> command: Win + R --> cmd --> c:\.....>pip install pillow Image creation and drawing Using the PIL library, you can create new images. The Image.new function takes an RGB palette type, a tuple with the size of the new image, and a color to fill the image with.
In order for the system to understand where to create the object, you need to save the *.py file. The image will be created in the same directory (folder). After executing the program folder, we get the following image:
To draw graphic primitives, Draw objects from the PIL.ImageDraw module. This object has many tools for creating graphic primitives: lines, ellipses, points, rectangles, arcs, etc.
Draw line: draw.line((x0, y0, x1, y1), fill=color, width=n)
Draw a green line from bottom-left to top-right with a width of 3 pixels:
Draw an ellipse draw.ellipse((x0, y0, x1, y1), fill=color, width=n)
Draw a rectangle draw.rectangle((x0, y0, x1, y1), fill=color, outline=color) # outline is a border of rectangle
Draw polygon draw.polygon(((x0, y0), (x1, y1), (x2, y2), (x3, y3), (x4, y4)), color)
Questions: 1. Name the library for working with the Draw module. 2. Explain what the RGB color model means. 3. List the graphical functions of the module Draw and describe the arguments of each. Exercises:
Tasks: | |
| |
Просмотров: 7712 | | |
Всего комментариев: 0 | |