From c0572790d20c81a690b538bcaaa95eeba796ea25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Thu, 6 Aug 2026 01:22:04 +0200 Subject: [PATCH 1/3] Attempts a more portable rgba extraction --- .../pixel/image/inspectors/imagemagick/ColorAt.php | 9 +++++++-- .../pixel/image/inspectors/imagemagick/TopColors.php | 11 ++++++++--- .../image/operations/imagemagick/ReplaceColorTest.php | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php b/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php index 28fb0d2c5..c4e38e6c8 100644 --- a/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php +++ b/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php @@ -47,8 +47,13 @@ public function inspect(object &$imageResource): mixed $pixel = $imageResource->getImagePixelColor($this->pixel->x, $this->pixel->y); - $rgba = $pixel->getColor(2); // 2 = RGBA normalized to 0-255 + $color = $pixel->getColor(1); - return new Color($rgba['r'], $rgba['g'], $rgba['b'], $rgba['a']); + $r = (int) round($color['r'] * 255); + $g = (int) round($color['g'] * 255); + $b = (int) round($color['b'] * 255); + $a = (int) round($color['a'] * 255); + + return new Color($r, $g, $b, $a); } } diff --git a/src/mako/pixel/image/inspectors/imagemagick/TopColors.php b/src/mako/pixel/image/inspectors/imagemagick/TopColors.php index bd3ae79f9..02d2620f4 100644 --- a/src/mako/pixel/image/inspectors/imagemagick/TopColors.php +++ b/src/mako/pixel/image/inspectors/imagemagick/TopColors.php @@ -53,13 +53,18 @@ public function inspect(object &$imageResource): mixed break; } - $rgba = $pixel->getColor(2); // 2 = RGBA normalized to 0-255 + $color = $pixel->getColor(1); - if ($hasAlphaChannel && $this->ignoreTransparent && $rgba['a'] === 0) { + $r = (int) round($color['r'] * 255); + $g = (int) round($color['g'] * 255); + $b = (int) round($color['b'] * 255); + $a = (int) round($color['a'] * 255); + + if ($hasAlphaChannel && $this->ignoreTransparent && $a === 0) { continue; } - $colors[] = new Color($rgba['r'], $rgba['g'], $rgba['b'], $rgba['a']); + $colors[] = new Color($r, $g, $b, $a); } return $colors; diff --git a/tests/unit/pixel/image/operations/imagemagick/ReplaceColorTest.php b/tests/unit/pixel/image/operations/imagemagick/ReplaceColorTest.php index 99b99593d..bcf5d1dfa 100644 --- a/tests/unit/pixel/image/operations/imagemagick/ReplaceColorTest.php +++ b/tests/unit/pixel/image/operations/imagemagick/ReplaceColorTest.php @@ -36,7 +36,7 @@ public function testReplaceColors(): void $image->apply(new ReplaceColor( Color::fromHex('#0376BB'), - new Color(0, 0, 0) + new Color(0, 0, 0, 127) )); $colors = $image->inspect(new TopColors); @@ -44,6 +44,7 @@ public function testReplaceColors(): void $this->assertCount(3, $colors); $this->assertSame('#000000', $colors[0]->toHexString()); + $this->assertSame('#0000007F', $colors[0]->toHexaString()); $this->assertSame('#B51700', $colors[1]->toHexString()); $this->assertSame('#047101', $colors[2]->toHexString()); } From f58b66d40b159544de21c8b1b5fea0335f86db37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Thu, 6 Aug 2026 01:31:52 +0200 Subject: [PATCH 2/3] Try getColorValue for alpha --- src/mako/pixel/image/inspectors/imagemagick/ColorAt.php | 2 +- src/mako/pixel/image/inspectors/imagemagick/TopColors.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php b/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php index c4e38e6c8..34ebf7bb1 100644 --- a/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php +++ b/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php @@ -52,7 +52,7 @@ public function inspect(object &$imageResource): mixed $r = (int) round($color['r'] * 255); $g = (int) round($color['g'] * 255); $b = (int) round($color['b'] * 255); - $a = (int) round($color['a'] * 255); + $a = (int) round($pixel->getColorValue(Imagick::COLOR_ALPHA) * 255); return new Color($r, $g, $b, $a); } diff --git a/src/mako/pixel/image/inspectors/imagemagick/TopColors.php b/src/mako/pixel/image/inspectors/imagemagick/TopColors.php index 02d2620f4..b92fcec59 100644 --- a/src/mako/pixel/image/inspectors/imagemagick/TopColors.php +++ b/src/mako/pixel/image/inspectors/imagemagick/TopColors.php @@ -58,7 +58,7 @@ public function inspect(object &$imageResource): mixed $r = (int) round($color['r'] * 255); $g = (int) round($color['g'] * 255); $b = (int) round($color['b'] * 255); - $a = (int) round($color['a'] * 255); + $a = (int) round($pixel->getColorValue(Imagick::COLOR_ALPHA) * 255); if ($hasAlphaChannel && $this->ignoreTransparent && $a === 0) { continue; From ffcfde5b5e265830ca0d8e05b61ab0bcafe5f7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Thu, 6 Aug 2026 01:37:27 +0200 Subject: [PATCH 3/3] Update tests.yml --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c38d0657f..841b45f55 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,10 @@ jobs: steps: - name: "Checkout code" uses: "actions/checkout@v7" + - name: "Pre-install system image libraries" + run: | + sudo apt-get update + sudo apt-get install -y libpng-dev libjpeg-dev libwebp-dev imagemagick - name: "Setup PHP" uses: "shivammathur/setup-php@v2" with: