手机版

php图像合成方法(多幅图像合成一幅)

时间:2021-09-03 来源:互联网 编辑:宝哥软件园 浏览:

1.多张图片组合成一张,例如:

图片合成可以显示在浏览器上,同时保存在文件夹下

例子如下:

?php /** *图片合并**/$pic_list=array('img2.png ',' img2.png ',' img2.png ',' img2.png ',' img2.png ',' img2.png ',' img2.png ',' img2。png ');$ pic _ list=array _ slice($ pic _ list,0,9);//只操作前9个图片$ bg _ w=150//背景图片宽度$ bg _ h=150//背景图片高度$ background=imagecreatetrue color($ BG _ w,$ BG _ h);//背景图片$ color=imagecolor allocate(背景,202,201,201美元);//为真彩色画布创建白色背景,再设置为透明imagefill($background,0,0,$ color);imagecolor透明($背景,$颜色);$ pic _ count=count($ pic _ list);$ linear=array();//需要换行的位置$ space _ x=3;$ space _ y=3;$ line _ x=0;switch($ pic _ count){ case 1://正中间$ start _ x=int val($ BG _ w/4);//开始位置x $ start _ y=int val($ BG _ h/4);//开始位置y $ pic _ w=int val($ BG _ w/2);//宽度$ pic _ h=int val($ BG _ h/2);//高度打破;第2: //中间位置并排$ start _ x=2;$ start _ y=int val($ BG _ h/4)3;$ pic _ w=int val($ BG _ w/2)-5;$ pic _ h=int val($ BG _ h/2)-5;$ space _ x=5;打破;案例3: $ start _ x=40//开始位置x $ start _ y=5;//开始位置y $ pic _ w=int val($ BG _ w/2)-5;//宽度$ pic _ h=int val($ BG _ h/2)-5;//高度$ lineArr=数组(2);$ line _ x=4;打破;case 4: $ start _ x=4;//开始位置x $ start _ y=5;//开始位置y $ pic _ w=int val($ BG _ w/2)-5;//宽度$ pic _ h=int val($ BG _ h/2)-5;//高度$ lineArr=数组(3);$ line _ x=4;打破;case 5: $ start _ x=30//开始位置X $ start _ y=30//开始位置y $ pic _ w=int val($ BG _ w/3)-5;//宽度$ pic _ h=int val($ BG _ h/3)-5;//高度$ lineArr=数组(3);$ line _ x=5;打破;case 6: $ start _ x=5;//开始位置X $ start _ y=30//开始位置y $ pic _ w=int val($ BG _ w/3)-5;//宽度$ pic _ h=int val($ BG _ h/3)-5;//高度$ lineArr=数组(4);$ line _ x=5;打破;案例7: $ start _ x=53//开始位置x $ start _ y=5;//开始位置y $ pic _ w=int val($ BG _ w/3)-5;//宽度$ pic _ h=int val($ BG _ h/3)-5;//高度$ lineArr=数组(2,5);$ line _ x=5;打破;case 8: $ start _ x=30//开始位置x $ start _ y=5;//开始位置y $ pic _ w=int val($ BG _ w/3)-5;//宽度$ pic _ h=int val($ BG _ h/3)-5;//高度$ lineArr=数组(3,6);$ line _ x=5;打破;案例9:美元start _ x=5;//开始位置x $ start _ y=5;//开始位置y $ pic _ w=int val($ BG _ w/3)-5;//宽度$ pic _ h=int val($ BG _ h/3)-5;//高度$ lineArr=数组(4,7);$ line _ x=5;打破;} foreach($ pic _ list as $ k=$ pic _ path){ $ kk=$ k 1;if (in_array($kk,$ linear)){ $ start _ x=$ line _ x;$ start _ y=$ start _ y $ pic _ h $ space _ y;} $ PathInfo=PathInfo($ pic _ path);switch(strtolow($ PathInfo[' extension ']){ case ' jpg ' : case ' JPEG ' : $ imagecreatefrom JPEG=' imagecreatefrom JPEG ';打破;大小写" png " : $ imagecreatefrom JPEG=" imagecreatefrom png ";打破;大小写“gif”:默认值: $ imagecreatefrom JPEG=“imagecreatefromstring”;$ pic _ path=file _ get _ contents($ pic _ path);打破;} $ resource=$ imagecreatefrom JPEG($ pic _ path);//$start_x,$start_y副本图片在背景中的位置//0,0 被复制图片的位置//$pic_w,$pic_h副本后的高度和宽度imagecopyresized($background,$resource,$start_x,$start_y,0,0,$pic_w,$pic_h,imagesx($resource),imagesy($ resource));//最后两个参数为原始图片宽度和高度,倒数两个参数为复制时的图片宽度和高度$ start _ x=$ start _ x $ pic _ w $ space _ x;}标题(“内容类型:图像/jpg”);图像JPEG(美元)背景);imagegif($background,' ./hero _ gam。png ');以上这篇服务器端编程语言(专业超文本预处理器的缩写)图片合成方法(多张图片合成一张)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

版权声明:php图像合成方法(多幅图像合成一幅)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。

相关文章推荐