zoukankan      html  css  js  c++  java
  • PHP 生成二维码底部拼接文字和中间拼接logo

    图片合成

    /**
     * 图片合并
     * 将源图片覆盖到目标图片上
     * @param string $dstPath 目标图片路径
     * @param string $srcPath 源图片路径
     * @param int $dstX 源图片覆盖到目标的X轴坐标
     * @param int $dstY 源图片覆盖到目标的Y轴坐标
     * @param int $srcX
     * @param int $srcY
     * @param int $pct 透明度
     * @param string $filename 输出的文件名,为空则直接在浏览器上输出显示
     * @return string $filename 合并后的文件名
     */
    function picMerge($dstPath,$srcPath,$dstX=0,$dstY=0,$srcX=0,$srcY=0,$pct=100,$filename='')
    {
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dstPath));
        $src = imagecreatefromstring(file_get_contents($srcPath));
        //获取水印图片的宽高
        list($src_w, $src_h) = getimagesize($srcPath);
        //将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果
        imagecopymerge($dst, $src, 165, 225, 0, 0, $src_w, $src_h, 100);
        //如果水印图片本身带透明色,则使用imagecopy方法
        //imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h);
        //输出图片
        list($dst_w, $dst_h, $dst_type) = getimagesize($dstPath);
        switch ($dst_type) {
            case 1://GIF
                if(!$filename){
                    header('Content-Type: image/gif');
                    imagegif($dst);
                }else{
                    imagegif($dst,$filename);
                }
                break;
            case 2://JPG
                if(!$filename){
                    header('Content-Type: image/jpeg');
                    imagejpeg($dst);
                }else{
                    imagejpeg($dst,$filename);
                }
                break;
            case 3://PNG
                if(!$filename){
                    header('Content-Type: image/png');
                    imagepng($dst);
                }else{
                    imagepng($dst,$filename);
                }
                break;
            default:
                break;
        }
        imagedestroy($dst);
        imagedestroy($src);
        return $filename;
    }

    文字添加

    /**
     * 添加文字到图片上
     * @param $dstPath 目标图片
     * @param $fontPath 字体路径
     * @param $fontSize 字体大小
     * @param $text 文字内容
     * @param $dstY 文字Y坐标值
     * @param string $filename 输出文件名,为空则在浏览器上直接输出显示
     * @return string 返回文件名
     */
    function addFontToPic($dstPath,$fontPath,$fontSize,$text,$dstY,$filename='')
    {
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dstPath));
        //打上文字
        $fontColor = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
        $width = imagesx ( $dst );
        $height = imagesy ( $dst );
        $fontBox = imagettfbbox($fontSize, 0, $fontPath, $text);//文字水平居中实质
        imagettftext ( $dst, $fontSize, 0, ceil(($width - $fontBox[2]) / 2), $dstY, $fontColor, $fontPath, $text);
        //输出图片
        list($dst_w, $dst_h, $dst_type) = getimagesize($dstPath);
        switch ($dst_type) {
            case 1://GIF
                if(!$filename){
                    header('Content-Type: image/gif');
                    imagegif($dst);
                }else{
                    imagegif($dst,$filename);
                }
                break;
            case 2://JPG
                if(!$filename){
                    header('Content-Type: image/jpeg');
                    imagejpeg($dst);
                }else{
                    imagejpeg($dst,$filename);
                }
                break;
            case 3://PNG
                if(!$filename){
                    header('Content-Type: image/png');
                    imagepng($dst);
                }else{
                    imagepng($dst,$filename);
                }
                break;
            default:
                break;
        }
        imagedestroy($dst);
        return $filename;
    }
  • 相关阅读:
    LeetCode 515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
    LeetCode 114. 二叉树展开为链表(Flatten Binary Tree to Linked List)
    LeetCode 199. 二叉树的右视图(Binary Tree Right Side View)
    LeetCode 1022. 从根到叶的二进制数之和(Sum of Root To Leaf Binary Numbers)
    LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)
    LeetCode 617. 合并二叉树(Merge Two Binary Trees)
    LeetCode 206. 反转链表(Reverse Linked List) 16
    LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
    LeetCode 110. 平衡二叉树(Balanced Binary Tree) 15
    LeetCode 108. 将有序数组转换为二叉搜索树(Convert Sorted Array to Binary Search Tree) 14
  • 原文地址:https://www.cnblogs.com/chenkg/p/14529969.html
Copyright © 2011-2022 走看看