diff --git a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php index e33bb194..dea31b50 100644 --- a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php +++ b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php @@ -25,7 +25,7 @@ class LimitColorsCommand extends \Intervention\Image\Commands\AbstractCommand // define matte if (is_null($matte)) { - $matte = imagecolorallocatealpha($resource, 0, 0, 0, 127); + $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127); } else { $matte = $image->getDriver()->parseColor($matte)->getInt(); } diff --git a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php b/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php index 7f9c6690..4d886cff 100644 --- a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php +++ b/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php @@ -69,7 +69,7 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand // make image area transparent to keep transparency // even if background-color is set - $transparent = imagecolorallocatealpha($canvas->getCore(), 0, 0, 0, 127); + $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127); imagealphablending($canvas->getCore(), false); // do not blend / just overwrite imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent); diff --git a/src/Intervention/Image/Gd/Source.php b/src/Intervention/Image/Gd/Source.php index 8cba903f..bf5acf70 100644 --- a/src/Intervention/Image/Gd/Source.php +++ b/src/Intervention/Image/Gd/Source.php @@ -110,10 +110,6 @@ class Source extends \Intervention\Image\AbstractSource */ public function gdResourceToTruecolor(&$resource) { - if (imageistruecolor($resource)) { - return true; - } - $width = imagesx($resource); $height = imagesy($resource); @@ -122,7 +118,7 @@ class Source extends \Intervention\Image\AbstractSource // fill with transparent color imagealphablending($canvas, false); - $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127); + $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127); imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent); imagealphablending($canvas, true); diff --git a/src/Intervention/Image/Imagick/Encoder.php b/src/Intervention/Image/Imagick/Encoder.php index f2d6e327..78cf1fed 100644 --- a/src/Intervention/Image/Imagick/Encoder.php +++ b/src/Intervention/Image/Imagick/Encoder.php @@ -15,6 +15,9 @@ class Encoder extends \Intervention\Image\AbstractEncoder $compression = \Imagick::COMPRESSION_JPEG; $imagick = $this->image->getCore(); + $imagick->setImageBackgroundColor('white'); + $imagick->setBackgroundColor('white'); + $imagick = $imagick->flattenImages(); $imagick->setFormat($format); $imagick->setImageFormat($format); $imagick->setCompression($compression); diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php index 06de64f7..b70c6bd0 100644 --- a/tests/EncoderTest.php +++ b/tests/EncoderTest.php @@ -140,6 +140,9 @@ class EncoderTest extends PHPUnit_Framework_TestCase $imagick->shouldReceive('setimagecompression')->once(); $imagick->shouldReceive('setcompressionquality'); $imagick->shouldReceive('setimagecompressionquality'); + $imagick->shouldReceive('setimagebackgroundcolor'); + $imagick->shouldReceive('setbackgroundcolor'); + $imagick->shouldReceive('flattenimages')->andReturn($imagick); $imagick->shouldReceive('__toString')->once()->andReturn(sprintf('mock-%s', $type)); return $imagick; } diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 2db20a94..5fb709b7 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -1113,9 +1113,9 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertEquals(1, $c[3]); $c = $img->pickColor(0, 15); - $this->assertEquals(0, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(0, $c[2]); + $this->assertEquals(255, $c[0]); + $this->assertEquals(255, $c[1]); + $this->assertEquals(255, $c[2]); $this->assertEquals(0, $c[3]); } @@ -1137,9 +1137,9 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertEquals(1, $c[3]); $c = $img->pickColor(0, 15); - $this->assertEquals(0, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(0, $c[2]); + $this->assertEquals(255, $c[0]); + $this->assertEquals(255, $c[1]); + $this->assertEquals(255, $c[2]); $this->assertEquals(0, $c[3]); }