我的网站上有类似http://drksde.tk/images/F3-big.png的图片,用于用户的头像。并且每个用户都可以更改背景颜色,因为图像具有透明背景。我做完了!!非常感谢你的帮助!!
这是代码:
<?php
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
$cut = imagecreatetruecolor($src_w, $src_h);
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}
$background = imagecreatetruecolor(200, 200);
$color = imagecolorallocate($background, 255, 150, 0);
imagefill($background, 0, 0, $color);
$avatar = imagecreatefrompng('F3-big.png');
imagecopymerge_alpha($background, $avatar, 0, 0, 0, 0, 200, 200, 100);
header('Content-Type: image/png');
imagepng($background);
imagedestroy($background);
imagedestroy($avatar);
?>