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:
parent
54aa51efda
commit
50a16bbdc1
@ -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>
|
||||
|
@ -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');
|
||||
|
22
tests/Feature/Gd/ConvertPngGif.php
Normal file
22
tests/Feature/Gd/ConvertPngGif.php
Normal 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);
|
||||
}
|
||||
}
|
22
tests/Feature/Imagick/ConvertPngGif.php
Normal file
22
tests/Feature/Imagick/ConvertPngGif.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user