Skip to content

Commit

Permalink
Fix discarded alpha channel of watermark in PlaceModifier (#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel authored Jun 12, 2024
1 parent 13c166d commit ed6ddf4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/Imagick/Modifiers/PlaceModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function apply(ImageInterface $image): ImageInterface

// set opacity of watermark
if ($this->opacity < 100) {
$watermark->core()->native()->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
$watermark->core()->native()->setImageAlphaChannel(Imagick::ALPHACHANNEL_SET);
$watermark->core()->native()->evaluateImage(
Imagick::EVALUATE_DIVIDE,
$this->opacity > 0 ? 100 / $this->opacity : 1000,
Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Modifiers\PlaceModifier;
use Intervention\Image\Tests\GdTestCase;
use Intervention\Image\Drivers\Gd\Modifiers\PlaceModifier as PlaceModifierGd;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Modifiers\PlaceModifier::class)]
#[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\PlaceModifier::class)]
#[CoversClass(PlaceModifier::class)]
#[CoversClass(PlaceModifierGd::class)]
final class PlaceModifierTest extends GdTestCase
{
public function testColorChange(): void
Expand All @@ -27,7 +28,8 @@ public function testColorChangeOpacityPng(): void
$image = $this->readTestImage('test.jpg');
$this->assertEquals('febc44', $image->pickColor(300, 25)->toHex());
$image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50));
$this->assertEquals('987028', $image->pickColor(300, 25)->toHex());
$this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1);
$this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1);
}

public function testColorChangeOpacityJpeg(): void
Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Modifiers\PlaceModifier;
use Intervention\Image\Tests\ImagickTestCase;
use Intervention\Image\Drivers\Imagick\Modifiers\PlaceModifier as PlaceModifierImagick;

#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Modifiers\BlurModifier::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Modifiers\PlaceModifier::class)]
#[CoversClass(PlaceModifier::class)]
#[CoversClass(PlaceModifierImagick::class)]
final class PlaceModifierTest extends ImagickTestCase
{
public function testColorChange(): void
Expand All @@ -27,7 +28,8 @@ public function testColorChangeOpacityPng(): void
$image = $this->readTestImage('test.jpg');
$this->assertEquals('febc44', $image->pickColor(300, 25)->toHex());
$image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50));
$this->assertEquals('7f5e22', $image->pickColor(300, 25)->toHex());
$this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1);
$this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1);
}

public function testColorChangeOpacityJpeg(): void
Expand Down

0 comments on commit ed6ddf4

Please sign in to comment.