使用php生成、识别二维码
1、生成二维码
要求:
# 详见:https://packagist.org/packages/bacon/bacon-qr-code
php: ^8.1
iconv Library
imagick Library
# 或者:GD library
下载:
# 详见:https://packagist.org/packages/bacon/bacon-qr-code
composer require bacon/bacon-qr-code
php代码:
<?php
require __DIR__ . "/vendor/autoload.php";
use BaconQrCode\Renderer\GDLibRenderer;
use BaconQrCode\Writer;
$renderer = new GDLibRenderer(400);
$writer = new Writer($renderer);
$writer->writeFile('Hello World!', 'qrcode.png');
2、识别二维码
要求:
# 详见:https://packagist.org/packages/khanamiryan/qrcode-detector-decoder
PHP >= 8.1
GD Library
下载:
# 详见:https://packagist.org/packages/khanamiryan/qrcode-detector-decoder
composer require khanamiryan/qrcode-detector-decoder
php代码:
<?php
require __DIR__ . "/vendor/autoload.php";
use Zxing\QrReader;
$qrcode = new QrReader("qrcode.png");
$text = $qrcode->text();
var_dump($text);
详见:
bacon/bacon-qr-code - Packagist
khanamiryan/qrcode-detector-decoder - Packagist