jysperu / php-qr-code
基于 http://phpqrcode.sourceforge.net/
2.0.2
2022-03-09 03:42 UTC
Requires
- php: >=7.2
README
此源代码基于 phpqrcode.sourceforge.net 的 v1.1.4 (2010100721)
我只修改并修复了一点点代码。
要求
- PHP7.2
- PHP GD2 扩展,需要支持 JPEG 和 PNG
使用 Composer 快速开始
composer require jysperu/php-qr-code
<?php require_once '/path/to/vendor/autoload.php';
不使用 Composer 快速开始
<?php spl_autoload_register(function ($class) { static $dir = '/path/to/src'; static $spc = '\\'; $class = trim($class, $spc); $parts = explode($spc, $class); $base = array_shift($parts); if ($base <> 'QRcode' or count($parts) === 0) return; $parts = implode(DIRECTORY_SEPARATOR, $parts); $file = $dir . DIRECTORY_SEPARATOR . $parts . '.php'; if (file_exists($file)) require_once $file; });
示例
保存 PNG 图像
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $dest = __DIR__ . '/qr.png'; QRcode :: png ($data, $dest, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: New file
保存 WEBP 图像
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $dest = __DIR__ . '/qr.webp'; QRcode :: webp ($data, $dest, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: New file
打印 PNG 图像
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; QRcode :: png ($data, FALSE, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: Header: Content-type: image/png
打印 WEBP 图像
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; QRcode :: webp ($data, FALSE, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: Header: Content-type: image/webp
获取 PNG 图像数据
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $base64_data = QRcode :: base64_png ($data, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: $base64_data = data:image/png;base64,....
获取 WEBP 图像数据
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $base64_data = QRcode :: base64_webp ($data, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: $base64_data = data:image/webp;base64,....