Laravel + ThinkPhP 海报生成

相关资料:

小程序 | EasyWeChat

二维码生成

php 复制代码
public function test(){
  $config = [
    'app_id' => 'appid',
    'secret' => 'secret',
  ];

  $app = Factory::miniProgram($config);
  
  $response = $app->app_code->get('pages/index/index', [
    //二维码大小
    'width' => 150,
     //二维码颜色
    'line_color' => [
      'r' => 255,
      'g' => 255,
      'b' => 0,
    ],
  ]);

  if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
    //保存二维码
    $filename = $response->saveAs('qrcode', '123.png');
    //海报生成等逻辑写这个位置
    //...
    return $filename;
  }
}

海报生成

二维码生成好了之后,把二维码贴在海报的上面

php 复制代码
//首先我们读取二维码和海报背景图片
            
$posterImage = imagecreatefromjpeg('qrcode/bg.jpg'); //海报
$qrcodeImage = imagecreatefromjpeg('qrcode/123.jpg'); //小程序二维码
//字体
$fontFile = 'qrcode/ziti.ttf';
//文本颜色
$textColor = imagecolorallocate($posterImage, 126, 57, 26);
//字体大小
$textSize = 36;

$data = [
  //第一行文本 和 位置
  ['text' => '你好', 'x' => 110, 'y' => 600]
  //text 文本
  //x 左侧距离
  //y 头部距离
];
//海报上面写字
foreach ($data as $index => $textData) {
  $text = $textData['text'];
  $textX = $textData['x'];
  $textY = $textData['y'];
  imagettftext($posterImage, $textSize, 0, $textX, $textY, $textColor, $fontFile, $text);
}

//获取小程序二维码和海报图片的大小
            
$qrcodeWidth = imagesx($qrcodeImage);
$qrcodeHeight = imagesy($qrcodeImage);
            
//二维码大小
$qrcodeSize = 260; 
//二维码左侧距离
//手动设置用这个代码
// $qrcodeX = 90;
// 自动剧中用这个代码
//获取海报图片的宽度
$posterWidth = imagesx($posterImage);
//自动剧中
$qrcodeX = ($posterWidth - $qrcodeWidth) / 2;
//二维码头部距离
$qrcodeY = 1240;
//复制海报
imagecopyresampled($posterImage, $qrcodeImage, $qrcodeX, $qrcodeY, 0, 0, $qrcodeSize, $qrcodeSize, $qrcodeWidth, $qrcodeHeight);
//  如果还有图片要合并
$image3 = imagecreatefromjpeg('https://www.example.cn/zb1227/zx/201909/W020190909513625276746.jpg');
//  宽度
$newWidth = 900;
//  高度
$newHeight = 600;
// 调整图片尺寸
$resizedImage = imagescale($image3, $newWidth, $newHeight);
// 将调整后的图片复制到海报上
imagecopy($posterImage, $resizedImage, 90, 250, 0, 0, $newWidth, $newHeight);

// 海报保存
$outputPath = 'qrcode/poster.jpg';
imagejpeg($posterImage, $outputPath);

// 工作完毕
imagedestroy($posterImage);
imagedestroy($qrcodeImage);

return response()->json(['status'=>'success','msg'=>'海报生成成功']);

二维码生成成功

相关推荐
鱼鱼说测试4 小时前
Jenkins+Python自动化持续集成详细教程
开发语言·servlet·php
网硕互联的小客服8 小时前
Apache 如何支持SHTML(SSI)的配置方法
运维·服务器·网络·windows·php
苏琢玉9 小时前
如何让同事自己查数据?写一个零依赖 PHP SQL 查询工具就够了
mysql·php
全栈软件开发14 小时前
PHP域名授权系统网站源码_授权管理工单系统_精美UI_附教程
开发语言·ui·php·php域名授权·授权系统网站源码
mit6.82414 小时前
ubuntu远程桌面很卡怎么解决?
linux·ubuntu·php
奥格列的魔法拖鞋~1 天前
Docker-LNMP架构 创建多项目- 单个ngixn代理多个PHP容器服务
nginx·docker·eureka·架构·php·lnmp
皓空揽月1 天前
php+apache+nginx 更换域名
nginx·php·apache
我不是立达刘宁宇1 天前
php危险函数,二.assert()[现版本已弃用]
开发语言·php
liulanba2 天前
NAT 和 PNAT
开发语言·php
nvvas2 天前
PHP imagick扩展安装以及应用
php