1
=========================
2
The PIL.ImageChops Module
3
=========================
5
The PIL.ImageChops Module
6
=========================
8
The **ImageChops** module contains a number of arithmetical image
9
operations, called *channel operations* ("chops"). These can be used for
10
various purposes, including special effects, image compositions,
11
algorithmic painting, and more.
13
At this time, channel operations are only implemented for 8-bit images
16
Most channel operations take one or two image arguments and returns a
17
new image. Unless otherwise noted, the result of a channel operation is
18
always clipped to the range 0 to MAX (which is 255 for all modes
19
supported by the operations in this module).
24
**add(image1, image2, scale=1.0, offset=0)**
25
[`# <#PIL.ImageChops.add-function>`_]
26
Add images ((image1 + image2) / scale + offset).
28
Adds two images, dividing the result by scale and adding the offset.
29
If omitted, scale defaults to 1.0, and offset to 0.0.
35
**add\_modulo(image1, image2)**
36
[`# <#PIL.ImageChops.add_modulo-function>`_]
37
Add images without clipping ((image1 + image2) % MAX).
39
Adds two images, without clipping the result.
45
**blend(image1, image2, alpha)** [`# <#PIL.ImageChops.blend-function>`_]
46
Blend images using constant transparency weight.
48
Same as the **blend** function in the **Image** module.
50
**composite(image1, image2, mask)**
51
[`# <#PIL.ImageChops.composite-function>`_]
52
Create composite using transparency mask.
54
Same as the **composite** function in the **Image** module.
56
**constant(image, value)** [`# <#PIL.ImageChops.constant-function>`_]
62
**darker(image1, image2)** [`# <#PIL.ImageChops.darker-function>`_]
63
Compare images, and return darker pixel value (min(image1, image2)).
65
Compares the two images, pixel by pixel, and returns a new image
66
containing the darker values.
72
**difference(image1, image2)**
73
[`# <#PIL.ImageChops.difference-function>`_]
74
Calculate absolute difference (abs(image1 - image2)).
76
Returns the absolute value of the difference between the two images.
82
**duplicate(image)** [`# <#PIL.ImageChops.duplicate-function>`_]
87
**invert(image)** [`# <#PIL.ImageChops.invert-function>`_]
92
**lighter(image1, image2)** [`# <#PIL.ImageChops.lighter-function>`_]
93
Compare images, and return lighter pixel value (max(image1,
96
Compares the two images, pixel by pixel, and returns a new image
97
containing the lighter values.
103
**logical\_and(image1, image2)**
104
[`# <#PIL.ImageChops.logical_and-function>`_]
105
**logical\_or(image1, image2)**
106
[`# <#PIL.ImageChops.logical_or-function>`_]
107
**logical\_xor(image1, image2)**
108
[`# <#PIL.ImageChops.logical_xor-function>`_]
109
**multiply(image1, image2)** [`# <#PIL.ImageChops.multiply-function>`_]
110
Superimpose positive images (image1 \* image2 / MAX).
112
Superimposes two images on top of each other. If you multiply an
113
image with a solid black image, the result is black. If you multiply
114
with a solid white image, the image is unaffected.
120
**offset(image, xoffset, yoffset=None)**
121
[`# <#PIL.ImageChops.offset-function>`_]
124
Returns a copy of the image where data has been offset by the given
125
distances. Data wraps around the edges. If yoffset is omitted, it is
126
assumed to be equal to xoffset.
133
**screen(image1, image2)** [`# <#PIL.ImageChops.screen-function>`_]
134
Superimpose negative images (MAX - ((MAX - image1) \* (MAX - image2)
137
Superimposes two inverted images on top of each other.
143
**subtract(image1, image2, scale=1.0, offset=0)**
144
[`# <#PIL.ImageChops.subtract-function>`_]
145
Subtract images ((image1 - image2) / scale + offset).
147
Subtracts two images, dividing the result by scale and adding the
148
offset. If omitted, scale defaults to 1.0, and offset to 0.0.
154
**subtract\_modulo(image1, image2)**
155
[`# <#PIL.ImageChops.subtract_modulo-function>`_]
156
Subtract images without clipping ((image1 - image2) % MAX).
158
Subtracts two images, without clipping the result.