1
0
mirror of https://github.com/Intervention/image.git synced 2025-03-15 22:49:40 +01:00

Fix lost transparency when converting to GIF format

This commit is contained in:
Oliver Vogel 2024-08-14 14:57:09 +02:00
parent 54aa51efda
commit 50a16bbdc1
No known key found for this signature in database
GPG Key ID: 1B19D214C02D69BB
4 changed files with 49 additions and 2 deletions

View File

@ -4,6 +4,9 @@
<testsuite name="Unit Tests">
<directory suffix=".php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature Tests">
<directory suffix=".php">./tests/Feature</directory>
</testsuite>
</testsuites>
<source>
<include>

View File

@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Encoders;
use Exception;
use Intervention\Gif\Builder as GifBuilder;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\GifEncoder as GenericGifEncoder;
use Intervention\Image\Exceptions\EncoderException;
@ -26,11 +27,10 @@ class GifEncoder extends GenericGifEncoder implements SpecializedInterface
return $this->encodeAnimated($image);
}
$gd = $image->core()->native();
$gd = Cloner::clone($image->core()->native());
$data = $this->buffered(function () use ($gd) {
imageinterlace($gd, $this->interlaced);
imagegif($gd);
imageinterlace($gd, false);
});
return new EncodedImage($data, 'image/gif');

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Feature\Gd;
use Intervention\Image\ImageManager;
use Intervention\Image\Tests\GdTestCase;
class ConvertPngGif extends GdTestCase
{
public function testConversionKeepsTransparency(): void
{
$converted = ImageManager::gd()
->read(
$this->readTestImage('circle.png')->toGif()
);
$this->assertTransparency($converted->pickColor(0, 0));
$this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4);
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Feature\Imagick;
use Intervention\Image\ImageManager;
use Intervention\Image\Tests\ImagickTestCase;
class ConvertPngGif extends ImagickTestCase
{
public function testConversionKeepsTransparency(): void
{
$converted = ImageManager::imagick()
->read(
$this->readTestImage('circle.png')->toGif()
);
$this->assertTransparency($converted->pickColor(0, 0));
$this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4);
}
}