Skip to content

Commit

Permalink
Fix bug with overlapping colors in ResizeCanvasModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Aug 13, 2024
1 parent 54aa51e commit 44d3b85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Drivers/Imagick/Modifiers/ResizeCanvasModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ public function apply(ImageInterface $image): ImageInterface
if ($delta > 0) {
$draw->rectangle(
0,
0,
$delta,
$delta - 1,
$resize->height()
$resize->height() - $delta - 1
);
}

$draw->rectangle(
$size->width() + $delta,
0,
$delta,
$resize->width(),
$resize->height()
$resize->height() - $delta - 1
);

$frame->native()->drawImage($draw);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public function testModifyWithTransparency(): void
$this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2));
$this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17));
$this->assertTransparency($image->pickColor(12, 1));

$image = $this->createTestImage(16, 16)->fill('f00');
$image->modify(new ResizeCanvasModifier(32, 32, '00f5', 'center'));

$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 5));
$this->assertColor(0, 0, 255, 77, $image->pickColor(16, 5));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 5));

$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 16));
$this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 16));

$this->assertColor(0, 0, 255, 77, $image->pickColor(5, 30));
$this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30));
$this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30));
}

public function testModifyEdge(): void
Expand Down

0 comments on commit 44d3b85

Please sign in to comment.