PHP中实现合并图片的代码是什么
Admin 2022-08-13 群英技术资讯 596 次浏览
1 function combineImage($head_img,$middle_img,$footer_img,$save_path){ 2 $source_w = 400; 3 $source_h = 1142; 4 //取头部图片大小 5 $head_size = getimagesize($head_img); 6 $head_height = $head_size['1']; 7 $head_width = $head_size['0']; 8 $head_start_x = floor(($source_w-$head_width)/2);//头部开始位置 9 //取中间图片大小 10 $midd_size = getimagesize($middle_img); 11 $midd_height = $midd_size['1']; 12 $midd_width = $midd_size['0']; 13 $midd_start_y = $head_height-15;//中间开始Y坐标,因为头部的图片底部有空白,所以减去15 14 $midd_start_x = floor(($source_w-$midd_width)/2); 15 16 //取底部图片大小 17 $foot_size = getimagesize($footer_img); 18 $foot_height = $foot_size[1]; 19 $foot_width = $foot_size[0]; 20 $foot_start_x = floor(($source_w-$foot_width)/2);//底部图片x坐标 21 $foot_start_y = $source_h-$foot_height;//底部图片y坐标 22 23 $head = imagecreatefrompng($head_img); 24 $middle = imagecreatefrompng($middle_img); 25 $footer = imagecreatefrompng($footer_img); 26 27 $bg_img = imageCreatetruecolor($source_w,$source_h);//生成背景图片 28 $color = imagecolorallocate($bg_img, 255, 255, 255); //设置白色背景 29 imagefill($bg_img, 0, 0, $color);//背景色填充 30 imageColorTransparent($bg_img, $color);//透明 31 imagecopyresampled($bg_img,$head,$head_start_x,0,0,0,$head_width,$head_height,$head_width,$head_height); 32 imagecopyresampled($bg_img,$middle,$midd_start_x , $midd_start_y,0,0,$midd_width,$midd_height,$midd_width,$midd_height); 33 imagecopyresampled($bg_img,$footer,$foot_start_x , $foot_start_y,0,0,$foot_width,$foot_height,$foot_width,$foot_height); 34 35 imagepng($bg_img,$save_path ); 36 } 37 $head = dirname(__FILE__).'/public/images/head.png'; 38 $midd = dirname(__FILE__).'/public/images/midd1.png'; 39 $foot = dirname(__FILE__).'/public/images/foot1.png'; 40 $save_path = dirname(__FILE__)."/public/images/testcomblie.png"; 41 combineImage($head,$midd,$foot,$save_path);
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
phpstorm添加图片的方法:首先打开phpstorm软件并连续按两下shift键;接着输入命令“set Background Image”;最后设置好图片的清晰度即可。
这篇文章给大家分享的是有关php复选框的内容,对于复选框checkbox,我们比较常见的应用就是php表单提交,那么我们是如何判断复选框中的值是否被选中的呢?下面就给大家分享一下php复选框的实现。
安装开始在PHP中使用Redis前,我们需要确保已经安装了redis服务及PHPredis驱动,且你的机器上能正常使用PHP。
在PHP中,如果我们想要从数组中删除元素,那么我们就可以使用unset()函数,unset()函数能够用来销毁给定的变量。那么unset函数怎么用呢?下面小编就给大家介绍unset()函数的用法。
今天小编就为大家分享一篇关于PHP chop()函数讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008