XML technologies / SVG / Filters, transformations and gradients / Using and combining filters and lighting effectively / Filters and masks / The feComposite filter element

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The element <feComposite> combines filter results, “adding” individual pixels from two images according to the chosen method. These attributes are available in addition to the universal attributes:

Using this element requires at least one additional element. Its result and the original image or its alpha channel can then be merged with the filter element <feComposite>. The following example shows the different operators’ results, applied here to the parent groups.

...
  <defs>
    <filter id="arithmetic">
      <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="Schatten"/>
      <feComposite in="SourceGraphic" in2="Schatten" operator="in"/>
    </filter>
    <filter id="out">
      <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="Schatten"/>
      <feOffset dx="+3" dy="+3" in="Schatten" result="Schatten"/>
      <feComposite in="SourceGraphic" in2="Schatten" operator="out"/>
    </filter>
    <filter id="atop">
      <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="Schatten"/>
      <feOffset dx="+3" dy="+3" in="Schatten" result="Schatten"/>
      <feComposite in="SourceGraphic" in2="Schatten" operator="atop" />
    </filter>
    <filter id="xor">
      <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="Schatten"/>
      <feOffset dx="+3" dy="+3" in="Schatten" result="Schatten"/>  
      <feComposite in="SourceGraphic" in2="Schatten" operator="xor" />
    </filter>
    <desc>Es folgen die Farbverläufe</desc>
    ... 
  </defs>
  <g transform="translate(0,0)" style="filter:url(#arithmetic)">
    <g transform="translate(20,20), scale(0.7)" >
      <desc>Der Button</desc>
      <circle cx="25" cy="25" r="25" style="stroke-width:1;stroke-opacity:0.8;stroke:rgb(222,0,0);fill-opacity:1;opacity:1;fill:url(#runderVerlauf)"/>
      <ellipse cx="25" cy="15" rx="20" ry="12" style="stroke-width:1;stroke:none;fill-opacity:1;opacity:1;fill:url(#linearerVerlauf)"/>
    </g>
    <g transform="translate(120,20)">
      <desc>Der Text mit Rechteck</desc>
      <rect x="0" y="0" width="150" height="75" style="fill:red;stroke:black;stroke-width:1"/>
      <text id="iText" x="20" y="55" style="fill-opacity:1;font-family:'Arial Black';font-size:46;stroke:black;fill:yellow">SVG</text>
    </g>
  </g>
...

Filter results with arithmetic, over, in, out, atop and xor

Figure: Filter results with arithmetic, over, in, out, atop and xor.

   

 

 

 

back to top