본문 바로가기
svg

svg mask with linearGradient and radialGradient

by peach1227 2023. 10. 8.
<svg viewBox="-135 -45 270 90" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <linearGradient id="grad_mask" x1="0%" x2="100%" y1="0%" y2="100%">
      <stop offset="0.4" stop-color="#000000"></stop>
      <stop offset="0.5" stop-color="#ffffff"></stop>
    </linearGradient>
    <radialGradient id="myGradient">
      <stop offset="50%" stop-color="white" />
      <stop offset="60%" stop-color="black" />
    </radialGradient>
    <mask id="mask">
      <rect x="-135" y="-45" width="270" height="90" fill="url(#grad_mask)"></rect>
    </mask>
    <mask id="mask2">
  <circle cx="0" cy="0" r="90" fill="url('#myGradient')" />
    </mask>

  </defs>
  <g transform="translate(0,0)">
    <image x="-135" y="-45" width="270" height="90" mask="url(#mask)" xlink:href="https://tistory4.daumcdn.net/tistory/6522157/skin/images/Hydrangeas.jpg"></image>
  </g>

  <g transform="translate(0,0)">
    <image x="-135" y="-45" width="270" height="90" mask="url(#mask2)" xlink:href="https://tistory4.daumcdn.net/tistory/6522157/skin/images/Hydrangeas.jpg"></image>
  </g>
</svg>
반응형