kshan / postermaker
基于 GD 库的海报制作工具。一个用 PHP 生成海报的神器。
dev-master
2021-10-21 04:25 UTC
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-09-21 10:38:52 UTC
README
基于 gd 库的海报制作工具。 (PHP) 一个用 PHP 生成海报的神器
用法
例如在文件 someaction.php 中使用:
use \Kshan\PosterMaker\Postermaker;
$poster = new Postermaker(800, 1100);
$poster
->addImg('./bg.jpg', [0,0], [800, 1100])
->addImg('./data/upload/cover.jpg', [30,30],[740, 500])
->addImg('./data/upload/avatar.png', [520,620],[200, 200])
->addText('2020雅思口语刷题班', 30, [30,610], [255, 255, 255])
->addText('授课老师:Rico', 24, [30,720], [255, 255, 255])
->addText('coolhand', 24, [30,870], [255, 255, 255])
->addText('邀请你一起学习', 24, [30, 910], [255, 255, 255])
->addText('长按扫码听课', 24, [30,950], [255, 255, 255])
->addQrCode('http://com/123', [500,800],[250,250])
->render();
安装
composer require kshan/postermaker
addImg
按大小创建海报
$poster = new \PosterMaker\Postermaker(800, 1100); // (width, height)
addImg
添加图片 (图片路径, [x坐标, y坐标], [width, height])
$poster->addImg('./data/upload/cover.jpg', [30,30],[740, 500])
addText
添加文字 (文字内容, 字体大小, [x坐标, y坐标], 颜色[R,G,B]),坐标设为 'center' 代表居中
$poster->addText('2020雅思口语刷题班', 30, ['center',610], [255, 255, 255])
addQrCode
添加二维码 (文字内容, [x坐标, y坐标], [width, height], 空白区域大小)
$poster->addQrCode('http://com/123', [500,800],[250,250], 4)
render
添加文字 (文字内容, 字体大小, [x坐标, y坐标], 颜色[R,G,B])
$poster->render('./save.png'); // 保持为图片
// or
$poster->render(); // show image in html: `<img src="someaction.php" style="border-radius: 20px;"/>`
在 Thinkphp 等框架中使用
因为有些 PHP 框架的控制器默认输出 html,所以如果在控制器中直接输出图片,需要在控制器最后一行加上:
return response()->contentType('image/png');
或者使用 exit
exit();