icarexm/poster

the new poster extend

dev-master 2020-05-26 14:20 UTC

This package is auto-updated.

Last update: 2024-04-26 22:50:00 UTC


README

使用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());
        }

生成后的海报效果如下: