-
Notifications
You must be signed in to change notification settings - Fork 5
/
25_draw_grid.py
executable file
·47 lines (36 loc) · 1.13 KB
/
25_draw_grid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# vim: set fileencoding=utf-8
#
# (C) Copyright 2020 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
from PIL import Image, ImageDraw
filename = "Lenna.png"
try:
# načtení originálního obrázku Leny
test_image = Image.open(filename)
test_image.load()
# objekt umožňující kreslení do obrázku
draw = ImageDraw.Draw(test_image)
# rozměry obrázku
width = test_image.size[0]
height = test_image.size[1]
# vertikální úsečky
for x in range(0, width, 30):
draw.line((x, 0, x, height - 1), fill=(255, 255, 255))
# horizontální úsečky
for y in range(0, height, 30):
draw.line((0, y, width - 1, y), fill=(255, 255, 255))
# uložení upraveného obrázku
test_image.save("grid.png")
# zobrazení upraveného obrázku
test_image.show()
except Exception as e:
print(e)