@@ -57,6 +57,43 @@ Color names
57
57
58
58
See :ref: `color-names ` for the color names supported by Pillow.
59
59
60
+ Alpha channel
61
+ ^^^^^^^^^^^^^
62
+
63
+ By default, when drawing onto an existing image, the image's pixel values are simply
64
+ replaced by the new color::
65
+
66
+ im = Image.new("RGBA", (1, 1), (255, 0, 0))
67
+ d = ImageDraw.Draw(im)
68
+ d.rectangle((0, 0, 1, 1), (0, 255, 0, 127))
69
+ assert im.getpixel((0, 0)) == (0, 255, 0, 127)
70
+
71
+ # Alpha channel values have no effect when drawing with RGB mode
72
+ im = Image.new("RGB", (1, 1), (255, 0, 0))
73
+ d = ImageDraw.Draw(im)
74
+ d.rectangle((0, 0, 1, 1), (0, 255, 0, 127))
75
+ assert im.getpixel((0, 0)) == (0, 255, 0)
76
+
77
+ If you would like to combine translucent color with an RGB image, then initialize the
78
+ ImageDraw instance with the RGBA mode::
79
+
80
+ from PIL import Image, ImageDraw
81
+ im = Image.new("RGB", (1, 1), (255, 0, 0))
82
+ d = ImageDraw.Draw(im, "RGBA")
83
+ d.rectangle((0, 0, 1, 1), (0, 255, 0, 127))
84
+ assert im.getpixel((0, 0)) == (128, 127, 0)
85
+
86
+ If you would like to combine translucent color with an RGBA image underneath, you will
87
+ need to combine multiple images::
88
+
89
+ from PIL import Image, ImageDraw
90
+ im = Image.new("RGBA", (1, 1), (255, 0, 0, 255))
91
+ im2 = Image.new("RGBA", (1, 1))
92
+ d = ImageDraw.Draw(im2)
93
+ d.rectangle((0, 0, 1, 1), (0, 255, 0, 127))
94
+ im.paste(im2.convert("RGB"), mask=im2)
95
+ assert im.getpixel((0, 0)) == (128, 127, 0, 255)
96
+
60
97
Fonts
61
98
^^^^^
62
99
0 commit comments