外观
海报
php
use \app\poster\Poster;
// 获取用户ID,如果没有提供,则默认为0
$user_id = input("request.user_id", 0);
// 创建一个新的海报对象,宽度为750像素,高度为1334像素
$poster = new \app\poster\Poster(750, 1334);
// 设置海报的用户ID
$poster->set_user_id($user_id)->bgColor('#ffffff');
// 在海报上添加一张图片,图片的URL为指定的链接
$poster->image("https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/6229c3105a7e3f031056eb04/674d5bf04ae84d00121e9250/17343126794552918556.png")->width(750)->height(1000);
// 在海报上添加一行元素,并设置其边距
$poster->row(function (Poster $poster) {
$poster->text("如何拥有健康生活")->fontSize(40);
$poster->text("#健康生活 #营养健康")->fontSize(32)->top(32)->color('#1e66a6');
$poster->col(function (Poster $poster) {
$poster->image("https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/6229c3105a7e3f031056eb04/674d5bf04ae84d00121e9250/17343126795681500002.png")->width(33)->height(33);
$poster->text("121人觉得很赞")->left(10)->fontSize(30)->color('#8e8e8e');
}, 0, 24);
}, 26, 36);
// 在海报上添加小程序码元素,内容为指定的链接,位置在右下角,距离左边26像素,距离顶部80像素,并且是固定的
$poster->mpcode("/pages/home/home?a=1")->position(ImagePosition::$bottom_right)->left(26)->top(80)->fixed();
// 绘制海报并获取海报的URL
$url = $poster->draw();
// 返回成功的JSON响应,包含海报的URL
success_json(["url"=>$url]);