LEN

PHP endroid/qrcode 初体验
composer: https://packagist.org/packages/endroid/qrcode生...
扫描右侧二维码阅读全文
21
2017/09

PHP endroid/qrcode 初体验

composer: https://packagist.org/packages/endroid/qrcode

生成二维码:

public function getQrcode()
{
    // Create a basic QR code
    $qrCode = new QrCode('Life is too short to be generating QR codes');
    $qrCode->setSize(300);

    // Set advanced options
    $qrCode
        ->setWriterByName('png')
        ->setMargin(10)
        ->setEncoding('UTF-8')
        ->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH)
        ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0])
        ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255])
        ->setLabel('Scan the code', 16, VENDOR_DIR.'endroid/qrcode/assets/noto_sans.otf', LabelAlignment::CENTER)
        ->setLogoPath(VENDOR_DIR.'endroid/qrcode/assets/symfony.png') //中心图
        ->setLogoWidth(150)
        ->setValidateResult(false);

    // Directly output the QR code
    header('Content-Type: '.$qrCode->getContentType());
    echo $qrCode->writeString();

    // Save it to a file
    $qrCode->writeFile(VENDOR_DIR.'endroid/qrcode/qrcode.png');

    // Create a response object
    $response = new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);;
}

挺好用哦 收藏一下

最后修改:2017 年 09 月 21 日 02 : 33 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论