Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions src/mako/pixel/image/inspectors/imagemagick/ColorAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 8 additions & 3 deletions src/mako/pixel/image/inspectors/imagemagick/TopColors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ 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);

$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());
}
Expand Down
Loading