Path: blob/main/files/en-us/web/svg/element/fecomposite/index.md
6578 views
------{{SVGRef}}
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 {{SVGAttr("in")}} attribute
(the MDN logo) is placed over the destination graphic defined by the
{{SVGAttr("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 result = k1*i1*i2 + k2*i1 + k3*i2 + k4 where:
|
Usage context
{{svginfo}}
Attributes
Global attributes
{{SVGAttr("class")}}
{{SVGAttr("style")}}
Specific attributes
{{SVGAttr("in")}}: First input for the given filter primitive.
{{SVGAttr("in2")}}: Second input for the given filter primitive (works the same as the
inattribute).{{SVGAttr("operator")}}:
over|in|out|atop|xor|lighter|arithmetic{{SVGAttr("k1")}}, {{SVGAttr("k2")}}, {{SVGAttr("k3")}}, {{SVGAttr("k4")}}: Values used for calculating the result pixel in
arithmetic{{SVGAttr("operator")}} filter primitives.
DOM Interface
This element implements the {{domxref("SVGFECompositeElement")}} interface.
Example
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:
BackgroundImagecannot 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 useBackgroundImage.
SVG
Result
{{EmbedLiveSample("Example", 100, 450)}}
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
{{SVGElement("filter")}}
{{SVGElement("animate")}}
{{SVGElement("set")}}
{{SVGElement("feBlend")}}
{{SVGElement("feColorMatrix")}}
{{SVGElement("feComponentTransfer")}}
{{SVGElement("feConvolveMatrix")}}
{{SVGElement("feDiffuseLighting")}}
{{SVGElement("feDisplacementMap")}}
{{SVGElement("feFlood")}}
{{SVGElement("feGaussianBlur")}}
{{SVGElement("feImage")}}
{{SVGElement("feMerge")}}
{{SVGElement("feMorphology")}}
{{SVGElement("feOffset")}}
{{SVGElement("feSpecularLighting")}}
{{SVGElement("feTile")}}
{{SVGElement("feTurbulence")}}




