PHP 图片合成 颜色少了很多..有没有办法解决?
具体代码如下:
<?php
$filename = 't.png';
$png = imagecreatefrompng($filename); header("content-type:image/png");
$img=ImageCreate(400,400);
$bgcolor=ImageColorAllocate($img,0,0,0);
$red=ImageColorAllocate($img,255,0,0);
$bgcolortrans=ImageColorTransparent($img,$bgcolor);imagecopy($img,$png,0,0,0,0,400,400);ImagePng($img);
ImageDestroy($img);
?>
实际原图:
合成后的图片:
具体代码如下:
<?php
$filename = 't.png';
$png = imagecreatefrompng($filename); header("content-type:image/png");
$img=ImageCreate(400,400);
$bgcolor=ImageColorAllocate($img,0,0,0);
$red=ImageColorAllocate($img,255,0,0);
$bgcolortrans=ImageColorTransparent($img,$bgcolor);imagecopy($img,$png,0,0,0,0,400,400);ImagePng($img);
ImageDestroy($img);
?>
实际原图:
合成后的图片:
因为调色板图像限制,颜色有限,所以不能用ImageCreate,要用imagecreatetruecolor来创造真彩色图像