Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 11, 2025
1 parent 48b6bc7 commit fd45f6b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/Drivers/Imagick/Modifiers/FillModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Imagick;
use ImagickDraw;
use ImagickPixel;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FillModifier as ModifiersFillModifier;
Expand All @@ -20,7 +19,7 @@ public function apply(ImageInterface $image): ImageInterface
$this->driver()->handleInput($this->color)
);

foreach ($image as $frame) {
foreach ($image->core()->native() as $frame) {
if ($this->hasPosition()) {
$this->floodFillWithColor($frame, $pixel);
} else {
Expand All @@ -31,14 +30,14 @@ public function apply(ImageInterface $image): ImageInterface
return $image;
}

private function floodFillWithColor(FrameInterface $frame, ImagickPixel $pixel): void
private function floodFillWithColor(Imagick $frame, ImagickPixel $pixel): void
{
$target = $frame->native()->getImagePixelColor(
$target = $frame->getImagePixelColor(
$this->position->x(),
$this->position->y()
);

$frame->native()->floodfillPaintImage(
$frame->floodfillPaintImage(
$pixel,
100,
$target,
Expand All @@ -49,16 +48,16 @@ private function floodFillWithColor(FrameInterface $frame, ImagickPixel $pixel):
);
}

private function fillAllWithColor(FrameInterface $frame, ImagickPixel $pixel): void
private function fillAllWithColor(Imagick $frame, ImagickPixel $pixel): void
{
$draw = new ImagickDraw();
$draw->setFillColor($pixel);
$draw->rectangle(
0,
0,
$frame->native()->getImageWidth(),
$frame->native()->getImageHeight()
$frame->getImageWidth(),
$frame->getImageHeight()
);
$frame->native()->drawImage($draw);
$frame->drawImage($draw);
}
}
13 changes: 13 additions & 0 deletions tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ public function testModifyKeepsResolution(): void
$image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000'));
$this->assertEquals(300, round($image->resolution()->perInch()->x()));
}

public function testMergeTransparentBackgrounds(): void
{
$image = $this->createTestImage(1, 1)->fill('f00');
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new CropModifier(3, 3, 0, 0, '00f7', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(0, 0, 255, 119, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(0, 0, 255, 119, $image->pickColor(2, 2));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function indexedDataProvider(): Generator
yield [
static::createTestImage(3, 2)->fill('ccc'), // new grayscale
new PngEncoder(indexed: true),
'grayscale', // result should be 'indexed' but there seems to be no way to force this with imagick
'indexed',
];
yield [
static::readTestImage('circle.png'), // truecolor-alpha
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,17 @@ public function testHalfTransparent(): void
$this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30));
}

public function testMergeTransparentBackgrounds(): void
{
$image = $this->createTestImage(1, 1);
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$image->modify(new CropModifier(3, 3, 0, 0, '00f7', 'center'));
$this->assertEquals(3, $image->width());
$this->assertEquals(3, $image->height());
$this->assertColor(0, 0, 255, 127, $image->pickColor(0, 0));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
$this->assertColor(0, 0, 255, 127, $image->pickColor(2, 2));
}
}

0 comments on commit fd45f6b

Please sign in to comment.