Skip to content

Commit 7e8eb0f

Browse files
committed
color circles
1 parent 42b0943 commit 7e8eb0f

12 files changed

+60
-0
lines changed

pillow/color circles/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## main.py
2+
3+
Using grayscale layers to create `RGB` image with color circles.
4+
5+
![#1](images/normal_rgb.png?raw=true)
6+
7+
Using inverted layers.
8+
9+
![#1](images/inverted_rgb.png?raw=true)
10+
11+
---
12+
13+
### Merging images using ImageMagick
14+
15+
$ montage -tile 4x1 normal_layer_r.png normal_layer_g.png normal_layer_b.png normal_rgb.png normal_result.png
16+
17+
$ montage -background black -tile 4x1 inverted_layer_r.png inverted_layer_g.png inverted_layer_b.png inverted_rgb.png inverted_result.png
18+
19+
![#1](images/normal_result.png?raw=true)
20+
21+
![#1](images/inverted_result.png?raw=true)
22+
2.08 KB
Loading
2.05 KB
Loading
2.19 KB
Loading
25.5 KB
Loading
4.61 KB
Loading
1.83 KB
Loading
1.79 KB
Loading
1.88 KB
Loading
25.3 KB
Loading
4.61 KB
Loading

pillow/color circles/main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from PIL import Image, ImageDraw
2+
3+
def synthese(red=255, green=255, blue=255, background=0, file_prefix=''):
4+
5+
# layers in greyscale
6+
layer_R = Image.new('L', (450, 450), background)
7+
layer_G = Image.new('L', (450, 450), background)
8+
layer_B = Image.new('L', (450, 450), background)
9+
10+
# draw circle on red layer
11+
draw_R = ImageDraw.Draw(layer_R)
12+
draw_R.ellipse((10,150,300,440), red)
13+
14+
# draw circle on green layer
15+
draw_G = ImageDraw.Draw(layer_G)
16+
draw_G.ellipse((150,150,440,440), green)
17+
18+
# draw circle on blue layer
19+
draw_B = ImageDraw.Draw(layer_B)
20+
draw_B.ellipse((75,10,375,300), blue)
21+
22+
#layer_R.show()
23+
#layer_G.show()
24+
#layer_B.show()
25+
26+
layer_R.save(file_prefix + 'layer_r.png')
27+
layer_G.save(file_prefix + 'layer_g.png')
28+
layer_B.save(file_prefix + 'layer_b.png')
29+
30+
# create RGB image using greyscale layers
31+
image_RGB = Image.merge('RGB', (layer_R, layer_G, layer_B))
32+
33+
# show it
34+
image_RGB.show()
35+
image_RGB.save(file_prefix + 'rgb.png')
36+
37+
synthese(255, 255, 255, 0, 'normal_')
38+
synthese(0, 0, 0, 255, 'inverted_')

0 commit comments

Comments
 (0)