当前位置: 首页 > 后端技术 > PHP

php图像合成

时间:2023-03-29 20:30:33 PHP

functionmergeImg($imgs){list($maxwidth,$maxheight)=getimagesize($imgs['dst']);//getimagesize()函数将测量任何GIF,JPG,PNG,SWF,SWC、PSD、TIFF、BMP、IFF、JP2、JPX、JB2、JPC、XBM或WBMP图像文件大小,并返回图像的尺寸以及文件类型和可用于IMG标签中的高度/宽度文本普通HTML文件字符串。$dests=imagecreatetruecolor($maxwidth,$maxheight);//imagecreatetruecolor()返回一个图像标识符,代表一个黑色图像,大小为xsize和ysize。$dstim=imagecreatefrompng($imgs['dst']);//imagecreatefrompng()返回一个图像标识符,表示从给定文件名中获取的图像。imagecopy($dests,$dstim,0,0,0,0,$maxwidth,$maxheight);//复制srcim图像中坐标从srcx,srcy开始,宽度为srcw,高度为srch的部分到dstim图像的坐标是dstx和dsty。imagedestroy($dstim);//销毁图像$srcim=imagecreatefrompng($imgs['src']);$srcinfo=getimagesize($imgs['src']);imagecopy($dests,$srcim,0,$maxheight/2,0,0,$srcinfo[0],$srcinfo[1]);图片销毁($srcim);header("内容类型:图片/jpeg");imagejpeg($dests);}$imgs=array('dst'=>'http://www.wangshangyou.com/content/uploadfile/201312/b3241386050881.png','src'=>'http://www.wangshangyou.com/content/上传文件/201312/72691386051117.png');mergeImg($imgs);