1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-17 19:26:25 +02:00

fixed issue when converting transparent images to non-transparent formats

This commit is contained in:
Oliver Vogel
2014-05-20 21:17:34 +02:00
parent e3f13700a9
commit 6afefddb44
6 changed files with 15 additions and 13 deletions

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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]);
}