PHP图片合并,图片加背景
废话不多说,直接上代码:
function generate($srcImg,$destImg,$bgIndex) { //读原图信息 $img = imagecreatefrompng($srcImg); $width=imagesx($img); $height=imagesy($img); //构建画布 $canvas = imagecreatetruecolor($width, $height); //确定背景颜色 $r=67;$g=142;$b=219; $color=imagecolorallocate($canvas, $r, $g, $b); //填充画布 imagefill($canvas, 0, 0, $color); //合并图像 imagecopy($canvas, $img, 0,0, 0,0, $width, $height); //输出文件 imagepng($canvas,$destImg); //销毁对象 imagedestroy($img); imagedestroy($canvas); }