dompdf / php-svg-lib

SVG file parsing / rendering library
GNU Lesser General Public License v3.0
1.39k stars 77 forks source link

SVG fill-opacity attribute not working when fill attribute is in rgb/rgba/hsl #109

Closed mhadar closed 4 months ago

mhadar commented 1 year ago

When you have fill set in rgb format, the fill-opacity is then not respected.

This produce opaque image, but it should be 50% transparent: `

`

php-svg-triangle-opaque

When we have fill set in hex color, then the image is correctly semitransparent: `

`

php-svg-triangle-transparent

Problem is this condition, in file src/Svg/Style.php on line 165: if ($value !== null && $value[3] !== 1 && array_key_exists("{$from}-opacity", $style_map) === true) { because $value[3] is number, when color is in hex format, but string when color is in rgb/rgba/hsl format. After I changed to this, the svg is correct: if ($value !== null && $value[3] != 1 && array_key_exists("{$from}-opacity", $style_map) === true) {

bsweeney commented 5 months ago

The issue appears to be that we were treating the parsed color value inconsistently. I modified the logic so that the parsed components are more consistently returned and handled as decimal values.