1

How do I create an image without losing all the colors? It is creating an image with speckles and changing the color number doesn't make a difference. The PNG image I start with (uploaded via PHP) is much sharper.

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

How do I create a paletted image png with more colors?

4

0 に答える 0