From c77ddc29f598b6823448e5178bd1092a11e4fe46 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 26 Jun 2014 16:58:34 +0200 Subject: [PATCH] fixed gif encoding looses transparency --- src/Intervention/Image/Gd/Decoder.php | 1 + tests/GdSystemTest.php | 14 ++++++++++++++ tests/ImagickSystemTest.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/Intervention/Image/Gd/Decoder.php b/src/Intervention/Image/Gd/Decoder.php index 536200f0..5f0cbda6 100644 --- a/src/Intervention/Image/Gd/Decoder.php +++ b/src/Intervention/Image/Gd/Decoder.php @@ -120,6 +120,7 @@ class Decoder extends \Intervention\Image\AbstractDecoder imagealphablending($canvas, false); $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127); imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent); + imagecolortransparent($canvas, $transparent); imagealphablending($canvas, true); // copy original diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 8ec310f8..4440ab3e 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -1506,6 +1506,20 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertInternalType('resource', $cln->getCore()); } + public function testGifConversionKeepsTransparency() + { + $save_as = 'tests/tmp/foo.gif'; + + // create gif image from transparent png + $img = $this->manager()->make('tests/images/star.png'); + $img->save($save_as); + + // new gif image should be transparent + $img = $this->manager()->make($save_as); + $this->assertTransparentPosition($img, 0, 0); + @unlink($save_as); + } + private function assertColorAtPosition($color, $img, $x, $y) { $pick = $img->pickColor($x, $y, 'hex'); diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php index 0ec1db41..944c8fe6 100644 --- a/tests/ImagickSystemTest.php +++ b/tests/ImagickSystemTest.php @@ -1487,6 +1487,20 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase $this->assertInstanceOf('Imagick', $cln->getCore()); } + public function testGifConversionKeepsTransparency() + { + $save_as = 'tests/tmp/foo.gif'; + + // create gif image from transparent png + $img = $this->manager()->make('tests/images/star.png'); + $img->save($save_as); + + // new gif image should be transparent + $img = $this->manager()->make($save_as); + $this->assertTransparentPosition($img, 0, 0); + @unlink($save_as); + } + private function assertColorAtPosition($color, $img, $x, $y) { $pick = $img->pickColor($x, $y, 'hex');