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: diff --git a/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php b/src/mako/pixel/image/inspectors/imagemagick/ColorAt.php index 28fb0d2c5..34ebf7bb1 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($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 bd3ae79f9..b92fcec59 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($pixel->getColorValue(Imagick::COLOR_ALPHA) * 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()); }