Skip to content

Commit

Permalink
test: GD resizeCanvas for pngs with transparent bg;
Browse files Browse the repository at this point in the history
  • Loading branch information
olexoliinyk0 authored Jul 9, 2024
1 parent 7ad2460 commit 60e8b7c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/Manipulations/ResizeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Spatie\Image\Drivers\ImageDriver;
use Spatie\Image\Image;

use function Spatie\Snapshots\assertMatchesImageSnapshot;

Expand All @@ -14,3 +15,18 @@

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
$targetFile = $this->tempDir->path("{$driver->driverName()}/resize-with-transparent-png.png");
$transparent = imagecolorallocatealpha($canvas->image, 255, 255, 255, 127);
expect($image->getHeight())->toEqual(923);
expect($image->pickColor(0, 0, \Spatie\Image\Enums\ColorFormat::Int))->toEqual($transparent);

// 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);
});

0 comments on commit 60e8b7c

Please sign in to comment.