安装2amigos
php composer.phar require "2amigos/yii2-qrcode-helper" "*"
$label = (new Label($text))
// ->useFont(__DIR__ . '/../resources/fonts/monsterrat.otf')
->useFont(__DIR__ . '/../../../vendor/2amigos/yii2-qrcode-helper/resources/fonts/noto_sans.otf')
->updateFontSize(8);
$qrCode = (new QrCode($url))
->useLogo(__DIR__.'/../../../web/images/niao.jpg')
->useForegroundColor(0, 0, 0)
->useBackgroundColor(200, 220, 210)
->useEncoding('UTF-8')
->setErrorCorrectionLevel(ErrorCorrectionLevelInterface::HIGH)
->setLogoWidth(30)
->setSize(150)
->setMargin(6)
->setLabel($label);
// $qrCode->writeFile(__DIR__ . '/code.png');
// display directly to the browser
// header('Content-Type: '.$qrCode->getContentType());
// echo $qrCode->writeString();
$img_data = $qrCode->writeDataUri();
return $img_data;
// echo "<img src='{$img_data}'>";die;