ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ <?php namespace addons\qrcode\controller; use Endroid\QrCode\QrCode; use think\addons\Controller; use think\Response; /** * 二维码生成 * */ class Index extends Controller { protected $model = null; public function _initialize() { parent::_initialize(); } public function index() { return $this->view->fetch(); } // 生成二维码 public function build() { $text = $this->request->get('text', 'hello world'); $size = $this->request->get('size', 250); $padding = $this->request->get('padding', 15); $errorcorrection = $this->request->get('errorcorrection', 'medium'); $foreground = $this->request->get('foreground', "#ffffff"); $background = $this->request->get('background', "#000000"); $logo = $this->request->get('logo'); $logosize = $this->request->get('logosize'); $label = $this->request->get('label'); $labelfontsize = $this->request->get('labelfontsize'); $labelhalign = $this->request->get('labelhalign'); $labelvalign = $this->request->get('labelvalign'); // 前景色 list($r, $g, $b) = sscanf($foreground, "#%02x%02x%02x"); $foregroundcolor = ['r' => $r, 'g' => $g, 'b' => $b]; // 背景色 list($r, $g, $b) = sscanf($background, "#%02x%02x%02x"); $backgroundcolor = ['r' => $r, 'g' => $g, 'b' => $b]; $qrCode = new QrCode(); $qrCode ->setText($text) ->setSize($size) ->setPadding($padding) ->setErrorCorrection($errorcorrection) ->setForegroundColor($foregroundcolor) ->setBackgroundColor($backgroundcolor) ->setLogoSize($logosize) ->setLabel($label) ->setLabelFontSize($labelfontsize) ->setLabelHalign($labelhalign) ->setLabelValign($labelvalign) ->setImageType(QrCode::IMAGE_TYPE_PNG); $fontPath = ROOT_PATH . 'public/assets/fonts/SourceHanSansK-Regular.ttf'; if (file_exists($fontPath)) { $qrCode->setLabelFontPath($fontPath); } if ($logo) { $qrCode->setLogo(ROOT_PATH . 'public/assets/img/qrcode.png'); } //也可以直接使用render方法输出结果 //$qrCode->render(); return new Response($qrCode->get(), 200, ['Content-Type' => $qrCode->getContentType()]); return $fontPath; } public function getimg(){ $url = "www.baidu.com"; $phone = "15555555555"; $domain = $this->request->domain(); $bigImgPath = $domain."/image/111.jpg"; $qCodePath = "http://ticket.cn/qrcode/build?text=http://".$url."&label=".$phone."&logo=1&labelhalign=0&labelvalign=3&foreground=%23ffffff&background=%23000000&size=90&padding=10&logosize=20&labelfontsize=11&errorcorrection=medium"; $bigImg = imagecreatefromstring(file_get_contents($bigImgPath)); $qCodeImg = imagecreatefromstring(file_get_contents($qCodePath)); list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath); imagecopymerge($bigImg, $qCodeImg, 330, 650, 0, 0, $qCodeWidth, $qCodeHight, 100); list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath); header("Content-type: image/gif"); imagepng($bigImg); die; } } ~~~