mirror of
https://github.com/Intervention/image.git
synced 2025-09-01 18:02:45 +02:00
backwards compatibility for imagepalettetotruecolor
This commit is contained in:
@@ -21,7 +21,8 @@ class Source extends \Intervention\Image\AbstractSource
|
|||||||
switch ($info[2]) {
|
switch ($info[2]) {
|
||||||
case IMAGETYPE_PNG:
|
case IMAGETYPE_PNG:
|
||||||
$core = imagecreatefrompng($path);
|
$core = imagecreatefrompng($path);
|
||||||
imagepalettetotruecolor($core);
|
// imagepalettetotruecolor($core);
|
||||||
|
$this->gdResourceToTruecolor($core);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAGETYPE_JPEG:
|
case IMAGETYPE_JPEG:
|
||||||
@@ -30,7 +31,8 @@ class Source extends \Intervention\Image\AbstractSource
|
|||||||
|
|
||||||
case IMAGETYPE_GIF:
|
case IMAGETYPE_GIF:
|
||||||
$core = imagecreatefromgif($path);
|
$core = imagecreatefromgif($path);
|
||||||
imagepalettetotruecolor($core);
|
// imagepalettetotruecolor($core);
|
||||||
|
$this->gdResourceToTruecolor($core);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -75,4 +77,37 @@ class Source extends \Intervention\Image\AbstractSource
|
|||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform GD resource into Truecolor version
|
||||||
|
*
|
||||||
|
* @param resource $resource
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function gdResourceToTruecolor(&$resource)
|
||||||
|
{
|
||||||
|
if (imageistruecolor($resource)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$width = imagesx($resource);
|
||||||
|
$height = imagesy($resource);
|
||||||
|
|
||||||
|
// new canvas
|
||||||
|
$canvas = imagecreatetruecolor($width, $height);
|
||||||
|
|
||||||
|
// fill with transparent color
|
||||||
|
imagealphablending($canvas, false);
|
||||||
|
$transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
|
||||||
|
imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent);
|
||||||
|
imagealphablending($canvas, true);
|
||||||
|
|
||||||
|
// copy original
|
||||||
|
imagecopy($canvas, $resource, 0, 0, 0, 0, $width, $height);
|
||||||
|
imagedestroy($resource);
|
||||||
|
|
||||||
|
$resource = $canvas;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1122,7 +1122,7 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testPickColorFromPalette()
|
public function testPickColorFromPalette()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/tile.png');
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
imagetruecolortopalette($img->getCore(), true, 200);
|
$img->limitColors(200);
|
||||||
|
|
||||||
$c = $img->pickColor(0, 0);
|
$c = $img->pickColor(0, 0);
|
||||||
$this->assertEquals(180, $c[0]);
|
$this->assertEquals(180, $c[0]);
|
||||||
|
Reference in New Issue
Block a user