forked from ramwin/python-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_test.py
More file actions
33 lines (22 loc) · 894 Bytes
/
image_test.py
File metadata and controls
33 lines (22 loc) · 894 Bytes
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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Xiang Wang @ 2019-07-19 18:34:55
from PIL import Image
def test():
green_image = Image.new("RGBA", (100, 100), 0xff00ff00)
red_image = Image.new("RGBA", (100, 100), 0xff0000ff)
half_red_image = Image.new("RGBA", (100, 100), 0x800000ff)
bg = Image.new("RGBA", (1000, 1000), 0xffffffff)
width = 10
height = 10
img1 = Image.alpha_composite(green_image, red_image)
bg.paste(img1, (width, height), img1) # 绿色加红色,变成红色
width += 110
img2 = Image.alpha_composite(green_image, half_red_image) # 绿色,半透明红色,变成了黯淡的黄色
bg.paste(img2, (width, height), img2)
width += 110
img3 = Image.composite(green_image, red_image, red_image)
bg.paste(img2, (width, height), img3)
bg.save("image_test.png")
if __name__ == '__main__':
test()