11-34-custom-svg-filter.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Custom filter via SVG</title>
  6. <style>
  7. /**
  8. * 1. Safari will position the filter wrong unless the element
  9. * is promoted to its own layer, here via the translateZ(0)-trick.
  10. */
  11. .filter-1977 {
  12. -webkit-filter: url(#filter-1977);
  13. filter: url(#filter-1977);
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <img src="img/cat.jpg" alt="Charles the Cat">
  19. <img class="filter-1977" src="img/cat.jpg" alt="Charles the Cat">
  20. <svg height="0" viewBox="0 0 100 100">
  21. <filter id="filter-1977"
  22. primitiveUnits="objectBoundingBox" color-interpolation-filters="sRGB">
  23. <feComponentTransfer result="contrastout">
  24. <feFuncR type="linear" slope="1.1" intercept="-0.05"/>
  25. <feFuncG type="linear" slope="1.1" intercept="-0.05"/>
  26. <feFuncB type="linear" slope="1.1" intercept="-0.05"/>
  27. </feComponentTransfer>
  28. <feComponentTransfer in="contrastout" result="brightnessout">
  29. <feFuncR type="linear" slope="1.1"/>
  30. <feFuncG type="linear" slope="1.1"/>
  31. <feFuncB type="linear" slope="1.1"/>
  32. </feComponentTransfer>
  33. <feColorMatrix in="brightnessout"
  34. type="saturate" values="1.3" result="img" />
  35. <feFlood flood-color="#f36abc" flood-opacity="0.3"
  36. x="0" y="0" width="1" height="1"
  37. result="overlay" />
  38. <feBlend in="overlay" in2="img" mode="screen" />s
  39. </filter>
  40. </svg>
  41. </body>
  42. </html>