Giter Site home page Giter Site logo

php-tools-poster's Introduction

使用Composer安装icarexm的海报生成类库:

composer require icarexm/poster:dev-master

生成二维码

在生成海报之前,我们需要优先生成二维码

假设当前需要生成的二维码值为https://www.mrye.xin网址,我们在控制器中添加如下代码:

$qrcode = new icarexm\poster\Qrcode(ROOT_PATH);
$qrcode = $qrcode->create('https://www.mrye.xin');
//绝对路径
echo $qrcode->getPathname();
//相对路径
echo $qrcode->getSrcname();

生成如下二维码:

生成海报

下面来看下海报操作类的基础方法。

控制器中添加如下的代码:


$qrcode = new icarexm\poster\Qrcode(ROOT_PATH);
$qrcodePath = $qrcode->create('https://www.mrye.xin')->getPathname();
$config = array(
            'image' => array(
                //二维码资源
                array(
                    //资源路径
                    'url'       => $qrcodePath,
                    //相当于x
                    'left'      => 904,
                    //相当于y
                    'top'       => 1816,
                    'right'     => 0,
                    'bottom'    => 0,
                    //宽度
                    'width'     => 279,
                    //高度
                    'height'    => 275,
                    //删除临时文件
                    'isUnlink'  => true,
                ),
                //用户头像
                array(
                    'url'       => 'mryelogo.jpg',
                    'left'      => 554,
                    'top'       => 1078,
                    'right'     => 0,
                    'bottom'    => 0,
                    'width'     => 197.25,
                    'height'    => 194.25,
                    'isUnlink'  => true,
                ),
            ),
            //用户昵称
            'text' => array(
                array(
                    'text'      => 'MrYe',
                    'left'      => 551,
                    'top'       => 336,
                    //字号
                    'fontSize'  => 38,
                    //字体颜色
                    'fontColor' => '#000000',
                )
            ),
        );

        try {

            //生成海报
            $poster = new icarexm\poster\Poster(ROOT_PATH);
            $poster->createPoster('haibao.jpg', $config);
            //绝对路径
            echo $poster->getPathname();
            //相对路径
            echo $poster->getSrcname();

        } catch (\Exception $exception) {

            exit('error:'.$exception->getMessage());
        }

生成后的海报效果如下:

php-tools-poster's People

Contributors

icarexm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.