网站预算怎么做,广河网站建设,网站项目有需要什么技术支持,WordPress生成分享图片图片合成的流程一般是#xff0c;获取图像资源——合成——输出。png图片#xff0c;一般就用imagecreatefrompng()获取资源。不过这个资源获取后是有白底的。所以需要用imagesavealpha()进行图像处理#xff0c;得到包含有透明背景的图像。//原始图像$dst img/1.png…图片合成的流程一般是获取图像资源——合成——输出。png图片一般就用imagecreatefrompng()获取资源。不过这个资源获取后是有白底的。所以需要用imagesavealpha()进行图像处理得到包含有透明背景的图像。//原始图像$dst img/1.png;//得到原始图片信息$dst_im imagecreatefrompng($dst);imagesavealpha($dst_im, true);//输出图片header(Content-type: image/png);imagepng($dst_im);资源获取后就是合成。合成的图像函数一般为imagecopymerge()和imagecopy ()两种。imagecopymerge ()函数可以支持两个图像叠加时设置叠加的透明度。imagecopy() 函数则不支持叠加透明。意思就是两个纯色块的图片用imagecopymerge()的时候可以设置叠加图片为半透明。而imagecopy ()则直接叠加。实际上PHP内部源码里imagecopymerge()在透明度参数为100时直接调用imagecopy()函数。然而imagecopy函数拷贝时可以保留png图像的原透明信息而imagecopymerge()却不支持图片的本身的透明拷贝。imagecopymerge() 在合成带有透明图层的图片是会在透明区域自动填充白色。所以要进行多张自带透明层的png图片合成时则需要imagecopy()函数。imagecopymerge()合成例子//原始图像$dst img/1.png;//得到原始图片信息$dst_im imagecreatefrompng($dst);$dst_info getimagesize($dst);//水印图像$src img/2.png;$src_im imagecreatefrompng($src);$src_info getimagesize($src);//水印透明度$alpha 100;imagesavealpha($dst_im, true);imagesavealpha($src_im, true);//合并水印图片imagecopy($dst_im,$src_im,$dst_info[0]-$src_info[0],$dst_info[1]-$src_info[1],0,0,$src_info[0],$src_info[1]);//输出合并后水印图片header(Content-type: image/png);imagepng($dst_im);效果图image.pngimagecopymerge()合成例子//原始图像$dst img/1.png;//得到原始图片信息$dst_im imagecreatefrompng($dst);$dst_info getimagesize($dst);//水印图像$src img/2.png;$src_im imagecreatefrompng($src);$src_info getimagesize($src);//水印透明度$alpha 100;imagesavealpha($dst_im, true);imagesavealpha($src_im, true);//合并水印图片imagecopymerge($dst_im,$src_im,$dst_info[0]-$src_info[0],$dst_info[1]-$src_info[1],0,0,$src_info[0],$src_info[1],$alpha);//输出合并后水印图片header(Content-type: image/png);imagepng($dst_im);效果图image.png多张png图合成$width 705;$height 670;$layers array();$layers[] imagecreatefrompng(img/1.png);$layers[] imagecreatefrompng(img/2.png);$layers[] imagecreatefrompng(img/3.png);$layers[] imagecreatefrompng(img/4.png);$image imagecreatetruecolor($width, $height); //建立个原图大小的画板$bg imagecolorallocatealpha($image , 0 , 0 , 0 , 127);//拾取个完全透明的颜色不要用imagecolorallocate拾色imagefill($image , 0 , 0 , $bg); //填充imagesavealpha($image, true); //设置保存PNG时保留透明通道信息for ($i 0; $i count($layers); $i) {imagecopy($image, $layers[$i], 0, 0, 0, 0, $width, $height); //合成图像}$filename img/file/.time()..png;//var_dump($filename);header(Content-type: image/png);imagepng($image);imagepng($image,$filename); //生成图片imagedestroy($image); //销毁占用效果图image.png