Duplicate (filter) id of inline SVG

后端 未结 1 952
悲哀的现实
悲哀的现实 2021-01-21 08:39

When creating an inline SVG with filters, I have to define an ID for the filter.

When I automatically generates several inline SVG with slight differences, the f

相关标签:
1条回答
  • 2021-01-21 09:19

    The workaround is to generate a unique or random filter ID for each SVG.

    <p>Image 1 Hue = 100</p><p>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="120">
      <filter id="colorchangerfilter-green" x="0" y="0" width="1" height="1">
        <feColorMatrix id="huefilter" type = "hueRotate" values = "100"/>
      </filter>
      <image 
    xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/archive/6/6e/20110118171033%21HTML5-logo.svg/120px-HTML5-logo.svg.png" width="120" height="120" filter="url(#colorchangerfilter-green)"/>
    </svg>
    </p><br>
    
    <p>Image 2 Hue = 200</p><p>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="120">
      <filter id="colorchangerfilter-blue" x="0" y="0" width="1" height="1">
        <feColorMatrix id="huefilter" type = "hueRotate" values = "200"/>
      </filter>
      <image 
    xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/archive/6/6e/20110118171033%21HTML5-logo.svg/120px-HTML5-logo.svg.png" width="120" height="120" filter="url(#colorchangerfilter-blue)"/>
    </svg>
    </p>
    

    That may sound simple but for me it's very unpractical. I would like to have a solution without filter IDs (I don't think this is possible) or with duplicate ID but without prevalence (maybe embedded into something?).

    0 讨论(0)
提交回复
热议问题