Duplicate (filter) embedded SVG identifier

When creating an embedded SVG with filters, I have to define an identifier for the filter.

When I automatically generate several built-in SVGs with slight differences, the filter of the first image prevails (overwrites) the filter of the following images (due to identifiers of repeated filters ).

Live demo much more clear: http://jsfiddle.net/9wqgS/

<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" 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)"/> </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" 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)"/> </svg> </p> 

Image 1 should be green (hue = 100), and image 2 should be blue (hue = 200). Instead, both images are green.

I am sending below a workaround to this problem, but I really would like to have a simpler solution ...

+1
source share
1 answer

The workaround is to generate a unique or random filter identifier 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> 

It may seem simple, but for me it is very impractical. I would like to have a solution without filter identifiers (I donโ€™t think this is possible) or with a duplicate identifier, but without prevailing (perhaps embedded in something?).

+2
source

Source: https://habr.com/ru/post/956945/


All Articles