Opacity is lost when converting RGB color to HEX color

Created on 3 September 2025, about 2 months ago

Problem/Motivation

When I color with (new ColorRB(...))->toHex(), the opacity value is lost. It's because incorrect value is passed to ColorHex() constructor inside ColorRGB::toHex().

Steps to reproduce

$color = (new ColorRGB(255,0,0,0.5))->toHex()

When you call $color->getOpacity(), it returns 0 instead of expected 0.5.

Proposed resolution

Fix ColorRGB::toHex() by replacing:

return new ColorHex(
      $this->intToColorHex($this->getRed()) . $this->intToColorHex($this->getGreen()) . $this->intToColorHex($this->getBlue()),
      (float) $this->intToColorHex((int) $this->getOpacity() * 255)
    );

with:

return new ColorHex(
      $this->intToColorHex($this->getRed()) . $this->intToColorHex($this->getGreen()) . $this->intToColorHex($this->getBlue()),
      $this->getOpacity()
    );
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇱Poland gugalamaciek

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024