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:
@@ -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();
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user