convertOneStopGradients
Converts the <linearGradient>
and <radialGradient>
nodes that are effectively a solid color to the color.
These nodes contain <stop>
elements, which represent various colors to transition between. However, if a gradient only contains a single <stop>
, then it's effecitively a solid fill.
Definitions of the gradients are removed, and the parent <defs>
node is removed if it has no children after optimization. The xlink:href
namespace is also removed if there are no remaining elements using this attribute.
Usage
svgo.config.js
module.exports = {
plugins: [
"convertOneStopGradients"
]
}
Demo
Live Editor
const svg = ` <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0 150 100 " width="150"> <!-- Created with love! --> <defs> <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/> </defs> <g> <use href="#circle" transform="skewX(16)"/> <rect id="useless" width="0" height="0" fill="#ff0000"/> </g> </svg> `; const svgoConfig = { js2svg: { indent: 2, pretty: true }, plugins: [ "convertOneStopGradients" ] } render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...