PHP 合并图片

<?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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值