如何在不丢失所有颜色的情况下创建图像?它正在创建一个带有斑点的图像,并且更改颜色编号并没有什么区别。我开始使用的PNG图像(通过PHP上传)非常清晰。
//Create an image from the source
$srcImage = imagecreatefromstring( file_get_contents( $sourcePath ) );
//Get the source width and height
list( $width, $height ) = getimagesize( $sourcePath );
//Create image to paint on
$canvas = imagecreatetruecolor( $width, $height );
//Add alpha for transparency
$bga = imagecolorallocatealpha( $canvas, 0, 0, 0, 127 );
imagecolortransparent( $canvas, $bga );
imagefill( $canvas, 0, 0, $bga );
//Convert to palette (ignores the number of colors)
imagetruecolortopalette( $canvas, true, 1000 );
//Retain transparency
imagesavealpha( $canvas, true );
//Save as PNG to file
imagepng( $canvas, $destPath );
//Remove temporary data
imagedestroy( $canvas );
如何创建具有更多颜色的调色板图像?