1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 17:41:58 +02:00

backwards compatibility for imagepalettetotruecolor

This commit is contained in:
Oliver Vogel
2014-05-13 16:56:54 +02:00
parent 7ad6697aff
commit a829c574a2
2 changed files with 38 additions and 3 deletions

View File

@@ -21,7 +21,8 @@ class Source extends \Intervention\Image\AbstractSource
switch ($info[2]) {
case IMAGETYPE_PNG:
$core = imagecreatefrompng($path);
imagepalettetotruecolor($core);
// imagepalettetotruecolor($core);
$this->gdResourceToTruecolor($core);
break;
case IMAGETYPE_JPEG:
@@ -30,7 +31,8 @@ class Source extends \Intervention\Image\AbstractSource
case IMAGETYPE_GIF:
$core = imagecreatefromgif($path);
imagepalettetotruecolor($core);
// imagepalettetotruecolor($core);
$this->gdResourceToTruecolor($core);
break;
default:
@@ -75,4 +77,37 @@ class Source extends \Intervention\Image\AbstractSource
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;
}
}

View File

@@ -1122,7 +1122,7 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
public function testPickColorFromPalette()
{
$img = $this->manager()->make('tests/images/tile.png');
imagetruecolortopalette($img->getCore(), true, 200);
$img->limitColors(200);
$c = $img->pickColor(0, 0);
$this->assertEquals(180, $c[0]);