PHP 合并图片,图片新增水印

private function imageMerge($file1,$file2){
        $filets['width'] = '300';//宽

        $filets['height'] = '300';//高

        $filets['x'] = ''; //x轴

        $filets['y'] =''; //y轴
        //本地的绝对路径
        $dst_path = $file1;//背景图
        $src_path= $file2; //头像
        $hz = substr(strrchr($dst_path, '.'), 1);
        $path = ‘C:/Users/pc/Desktop/hrchengtupian/public’;
        if(!file_exists($path)) mkdir($path);
        //生成新图片名
        $image = '/upload/nulimit/'.date("YmdHis").rand(1000,9999).".".$hz;
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dst_path));
        $src = imagecreatefromstring(file_get_contents($src_path));
        //获取水印图片的宽高
        $src_w =$filets['width'];$src_h=$filets['height'];
        list($src_w,$src_h) = getimagesize($src_path);
        //如果水印图片本身带透明色,则使用imagecopy方法
        imagecopy($dst, $src, $filets['x'],$filets['y'], 0, 0, $src_w, $src_h);
//        imagecopymerge($dst, $src, 200,380, 0, 0, 160, 60,100);
        //输出图片
        list($src_w, $src_h, $dst_type) = getimagesize($dst_path);
        switch ($dst_type) {
            case 1://GIF
                imagegif($dst, $path.$image);
                break;
            case 2://JPG
                imagejpeg($dst, $path.$image);
                break;
            case 3://PNG
                header('Content-Type: image/png');
                imagepng($dst, $path.$image);
                break;
            default:
                break;
        }
        return $image;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值