diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ffd95e..17e30fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ ### Fixed - PHP `8.4` deprecations +- Fix conversion from `RGBA` to `HSLA` ## 4.3.0 - 2025-03-20 diff --git a/src/RGBA.php b/src/RGBA.php index 118bd20..592cb2e 100644 --- a/src/RGBA.php +++ b/src/RGBA.php @@ -249,9 +249,10 @@ public function toHSLA(): HSLA } $hue *= 60; + $hue = ((int) \round($hue)) % 360; return HSLA::from( - Hue::of((int) \round($hue))->unwrap(), + Hue::of($hue)->unwrap(), Saturation::of((int) \round($saturation * 100))->unwrap(), Lightness::of((int) \round($lightness * 100))->unwrap(), $this->alpha, diff --git a/tests/RGBATest.php b/tests/RGBATest.php index 4c06739..9f2cf7c 100644 --- a/tests/RGBATest.php +++ b/tests/RGBATest.php @@ -522,4 +522,16 @@ public function testConvertible() $this->assertSame($rgba, $rgba->toRGBA()); } + + public function testRegressionToHSLA() + { + $colour = RGBA::from( + Red::at(205), + Green::at(32), + Blue::at(33), + Alpha::max(), + ); + + $this->assertInstanceOf(HSLA::class, $colour->toHSLA()); + } }