1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 01:29:51 +02:00

Fix bug with overlapping colors in ResizeCanvasModifier (#1394)

This commit is contained in:
Oliver Vogel
2024-08-14 15:07:00 +02:00
committed by GitHub
parent 50a16bbdc1
commit 3ba445b2d3
2 changed files with 24 additions and 8 deletions

View File

@@ -33,23 +33,25 @@ class ResizeCanvasModifier extends GenericResizeCanvasModifier implements Specia
$draw = new ImagickDraw();
$draw->setFillColor($background);
$delta = abs($resize->pivot()->x());
$delta_width = abs($resize->pivot()->x());
$delta_height = abs($resize->pivot()->y());
if ($delta > 0) {
if ($delta_width > 0) {
$draw->rectangle(
0,
0,
$delta - 1,
$resize->height()
$delta_height,
$delta_width - 1,
$delta_height + $size->height() - 1
);
}
$draw->rectangle(
$size->width() + $delta,
0,
$size->width() + $delta_width,
$delta_height,
$resize->width(),
$resize->height()
$delta_height + $size->height() - 1
);
$frame->native()->drawImage($draw);
}

View File

@@ -40,6 +40,20 @@ final class ResizeCanvasModifierTest extends ImagickTestCase
$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->assertEquals(32, $image->width());
$this->assertEquals(32, $image->height());
$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