<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/5/18 0018 * Time: 下午 18:30 */ $path_1 = '1.png'; $path_2 = '2.png'; $path4 = '3.png'; $weixin='baichen520'; $phone=18565871300; $file_name= './'; hebingImg($path_2, $path_1,$path4, $phone, $weixin, $file_name); /** * 图片合并 * @param string $path_2 二维码地址 * @param string $path_1 背景图地址 * @param string $phone 手机号码 * @param string $weixin 微信 * @return string */ function hebingImg($path_2, $path_1,$path4, $phone, $weixin, $file_name) {//加文字 //header('content-type:image/png'); $y2 = 1180; $y4 = 1240; if(!empty($phone)){ $image2_h=1210; }else{ $y4=1190; $image2_h=1150; } $image_2 = imagecreatefrompng($path_2); $image_4 = imagecreatefrompng($path4); $image_1 = imagecreatefrompng($path_1); list($width, $height) = getimagesize($path_2); $textcolor = imagecolorallocate($image_1, 255, 255, 255); //设置水印字体颜色 $font = "msyhbd.ttf"; //window定义字体 //$font = "/usr/share/fonts/simhei.ttf"; //linux定义字体 imagettftext($image_1, 28, 0, 285, $y2, $textcolor, $font, iconv_arr($phone));//将文字写到图片中 imagettftext($image_1, 28, 0, 285, $y4, $textcolor, $font, iconv_arr($weixin));//将文字写到图片中 $image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1)); imagecopymerge($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), 100); if(!empty($phone)){ imagecopyresampled($image_3, $image_2, 215, 1150, 0, 0, 50, 40, $width, $height); } if(!empty($weixin)){ imagecopyresampled($image_3, $image_4, 215, $image2_h, 0, 0, 50, 40, $width, $height); } imagepng($image_3, $file_name); imagedestroy($image_3); } /** * 将文本由UTF8编码转化为数字形式编码(HTML实体) * @param $arr 该参数可以为数组或者string * @author Steven lxq70361@qq.com */ function iconv_arr($arr){ if(is_array($arr)){ foreach($arr as $k=>$v){ $arr[$k] = iconv_arr($v); } }else{ $arr = mb_convert_encoding($arr, "html-entities","utf-8" ); } return $arr; }
PHP 合并图片
最新推荐文章于 2024-05-13 15:22:28 发布