PHP中实现合并图片的代码是什么
Admin 2022-08-13 群英技术资讯 698 次浏览
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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
PHP自动加载的方法有哪些?想要实现php自动加载,我们有两种方法,用__autoload函数和用spl自动加载,下面我们就来具体了解一下。
thinkphp是面向对象的;thinkphp是一个免费开源的、快速的、简单的、面向对象的轻量级PHP开发框架,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的开源轻量级PHP框架。
本篇文章给大家介绍一下解php7中curl文件上传出现错误的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
今天小编就为大家分享一篇关于PDO::prepare讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
这篇文章主要介绍了laravel框架创建授权策略,结合实例形式分析了laravel框架创建授权策略的相关步骤、实现方法与操作注意事项,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008