dompdf/php-svg-lib

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

mhadar opened this issue · 1 comments

mhadar commented

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:
<svg width="19" height="18" viewBox="0 0 19 18" xmlns="http://www.w3.org/2000/svg"> <path d="M9.5 0L18.5933 18H0.406734L9.5 0Z" fill="rgb(0, 154, 203)" fill-opacity="0.5"/> </svg>

php-svg-triangle-opaque

When we have fill set in hex color, then the image is correctly semitransparent:
<svg width="19" height="18" viewBox="0 0 19 18" xmlns="http://www.w3.org/2000/svg"> <path d="M9.5 0L18.5933 18H0.406734L9.5 0Z" fill="#009ACB" fill-opacity="0.5"/> </svg>

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) {