The <feComposite>SVG filter primitive performs the combination of two input images pixel-wise in image space using one of the Porter-Duff compositing operations: over, in, atop, out, xor, lighter, or arithmetic.
The table below shows each of these operations using an image of the MDN logo composited with a red circle:
Operation
Description
over
The source graphic defined by the in attribute (the MDN logo) is placed over the destination graphic defined by the in2 attribute (the circle).
This is the default operation, which will be used if no operation or an unsupported operation is specified.
in
The parts of the source graphic defined by the in attribute that overlap the destination graphic defined in the in2 attribute, replace the destination graphic.
out
The parts of the source graphic defined by the in attribute that fall outside the destination graphic defined in the in2 attribute, are displayed.
atop
The parts of the source graphic defined in the in attribute, which overlap the destination graphic defined in the in2 attribute, replace the destination graphic. The parts of the destination graphic that do not overlap with the source graphic stay untouched.
xor
The non-overlapping regions of the source graphic defined in the in attribute and the destination graphic defined in the in2 attribute are combined.
lighter
The sum of the source graphic defined in the in attribute and the destination graphic defined in the in2 attribute is displayed.
arithmetic
The arithmetic operation is useful for combining the output from the <feDiffuseLighting> and <feSpecularLighting> filters with texture data. If the arithmetic operation is chosen, each result pixel is computed using the following formula:
result = k1*i1*i2 + k2*i1 + k3*i2 + k4
where:
i1 and i2 indicate the corresponding pixel channel values of the input image, which map to in and in2 respectively
k1, k2, k3, and k4 indicate the values of the attributes with the same name.
Usage context
Categories
Filter primitive element
Permitted content
Any number of the following elements, in any order: <animate>, <set>
This example defines filters for each of the supported operations (over, atop, lighter, etc.), which composite an input SourceGraphic with an image of the MDN logo. The filters are each applied to a circle element, which is then used as the SourceGraphic.
Note:BackgroundImage cannot be used as a compositing source on modern browsers, so we can't define a filter that composites using whatever pixels happen to be under the filter as one of the sources. The approach taken here is a workaround because we can't use BackgroundImage.