扩展
1. 2amigos/qrcode-library
https://qrcode-library.readthedocs.io/en/latest
// in components config of Yii2 app 'components' => [ // ... 'qr' => [ 'class' => 'DaQrCodeComponentQrCodeComponent', // ... you can configure more properties of the component here ] // ... ] // on your controller's action 输出到浏览器 $qr = Yii::$app->get('qr'); Yii::$app->response->format = Response::FORMAT_RAW; Yii::$app->response->headers->add('Content-Type', $qr->getContentType()); return $qr ->setText('https://2amigos.us') ->setLabel('2amigos consulting group llc') ->writeString(); 保存二维码 $qr->setText('https://2amigos.us')->writeFile(路径);//路径一定要有效 否则报内容空,会让你觉得二维码没写入内容
直接调用
$qr = (new DaQrCodeQrcode($url))->setSize(250)->setMargin(5); // 把图片保存到文件中: $qr->writeFile('路径');
2.phpqrcode
http://phpqrcode.sourceforge.net/