Skip to content

Commit

Permalink
test: fix failing GD resizeCanvas for pngs with transparent bg;
Browse files Browse the repository at this point in the history
  • Loading branch information
olexoliinyk0 committed Jul 16, 2024
1 parent 60e8b7c commit 9d7996a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tests/Manipulations/ResizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
assertMatchesImageSnapshot($targetFile);
})->with('drivers');

it('can resize canvas of transparent pngs without loosing transparency when GD is used', function () {
$image = Image::useImageDriver(ImageDriver::Gd)->loadFile(getTestFile('transparent.png')); // 1640x923
it('can resize canvas of transparent PNGs without loosing transparency when GD is used', function (ImageDriver $driver) {
if ($driver->driverName() !== 'gd') {
return $this->expectNotToPerformAssertions();
}

$targetFile = $this->tempDir->path("{$driver->driverName()}/resize-with-transparent-png.png");
$transparent = imagecolorallocatealpha($canvas->image, 255, 255, 255, 127);
$image = $driver->loadFile(getTestFile('transparent.png')); // 1640x923
$transparentColor = imagecolorallocatealpha($image->image(), 255, 255, 255, 127);

expect($image->getHeight())->toEqual(923);
expect($image->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Int))->toEqual($transparent);
expect($image->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Int))->toEqual($transparentColor);

// make it square, so height is added top and bottom, bg transparent
$image->resizeCanvas(1640, 1640, \Spatie\Image\Enums\AlignPosition::Center, false, $image->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Rgba))->save($targetFile);

$targetImage = $driver->loadFile($targetFile);
expect($targetImage->getHeight())->toEqual(1640);
expect($targetImage->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Int))->toEqual($transparent);
});
expect($targetImage->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Int))->toEqual($transparentColor);
})->with('drivers');

0 comments on commit 9d7996a

Please sign in to comment.