use dh2y\qrcode\QRcode;
public function invite(){
$str = input('str','');
$qrc = new QRcode(['cache_dir' => 'upload/qrcode/'.date('Ymd')]);
$pth = $qrc ->png($str)->getPath();
$rot = app()->getRootPath().'public/';
$bgi = imagecreatefrompng($rot.'upload/static/poster.png');
$qri = imagecreatefrompng($rot.$pth);
//imagecopy($bgi,$qrc,10,20,0,0,225,225);
imagecopyresampled($bgi,$qri,50,50,0,0,200,200,imagesx($qri),imagesy($qri));
imagepng($bgi);
header('Content-Type: image/png');
imagedestroy($bgi);
imagedestroy($qri);
exit;
}
50是相对背景图左上角坐标,200是二维码缩放指定大小,效果如下
(PHP 图片合并,二维码海报,ThinkPhp 额外 use dh2y\qrcode\QRcode;)