vcode / qrcode
此包使用某些服务(如google qrcode)生成二维码。此包还支持将标志附加到二维码中。在Laravel框架中,它完全支持使用门面和blade助手。
v1.1.0
2015-05-11 00:19 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-28 17:21:48 UTC
README
简介
这是一个使用类似google qrcode等服务的包,用于生成二维码(目前,它仅支持google服务)。此包还支持在二维码中附加标志。在Laravel框架中,它完全支持使用门面和blade助手。
参考 https://developers.google.com/chart/infographics/docs/qr_code
安装
- 需要:php5-gd以写入图像。
Debian: apt-get install php5-gd
RedHat: yum install gd gd-devel php-gd
- 在
composer.json
文件中更新要求。
"vcode/qrcode": "dev-master"
- 然后您需要运行
composer update
- 或者
composer require "vcode/qrcode":"dev-master"
使用LARAVEL
文件: app/config/app.php
提供者
'providers' => array( 'Vcode\Qrcode\QrcodeServiceProvider', )
门面
'aliases' => array( 'Qrcode' => 'Vcode\Qrcode\Facades\Qrcode', )
使用Artisan创建配置文件
$ php artisan config:publish vcode/qrcode
在控制器中使用
$value = "https://github.com/tyanhly/vcode_qrcode"; //or for fully options //$value = array( // 'chs' => "250x250", // 'cht' => "qr", // 'chl' => "https://github.com/tyanhly/vcode_qrcode" // 'chld'=> "H|1", // H(QML)|1, H|2, H|3, H|4, H|10, H|40, // 'choe'=> "UTF-8" // UTF-8, Shift_JIS, ISO-8859-1 //); /** * @param array googleOption * @param string $destinate * @param string $logoPath * @param float $ratioOfLogoOnQrcode * @param int $qrCodeService */ //Qrcode::storageImage(array googleOption, string $destinate, string $logoPath, float $ratioOfLogoOnQrcode, int $qrCodeService); Qrcode::storageImage($value, "/tmp/destination.png", "logo.png", 0.3); /** * @param array googleOption * @param int $qrCodeService */ //Qrcode::render(array googleOption, int $qrCodeService); Qrcode::render($value); /** * @param array googleOption * @param string $logoPath * @param float $ratioOfLogoOnQrcode * @param int $qrCodeService */ //Qrcode::renderBase64(array googleOption, string $logoPath, float $ratioOfLogoOnQrcode, int $qrCodeService); Qrcode::renderBase64($value, "logo.png"); /** * @param array googleOption * @param string $logoPath * @param float $ratioOfLogoOnQrcode * @param int $qrCodeService */ //Qrcode::renderBase64Dome(array googleOption, string $logoPath, float $ratioOfLogoOnQrcode, int $qrCodeService); Qrcode::renderBase64Dom($value, "logo.png");
使用Blade助手
@qrcode("https://github.com/tyanhly/vcode_qrcode") @qrcodeBase64Dom("https://github.com/tyanhly/vcode_qrcode", "logo.png", 0.5) <img src="data:image/png;base64,@qrcodeBase64("https://github.com/tyanhly/vcode_qrcode", "logo.png", 0.5)" />
像PHP库一样使用
//Please, reference <this source>/example for more detail include 'vendor/autoload.php'; $qrcode = new Vcode\Qrcode\Qrcode(array( 'qrcode::google_config_default' => array( 'chs' => "250x250", 'cht' => "qr", 'chld'=> "H|1", // H(QML)|1, H|2, H|3, H|4, H|10, H|40, 'choe'=> "UTF-8" // UTF-8, Shift_JIS, ISO-8859-1 ), 'qrcode::template_simple' => './template', 'qrcode::storage_dir' => '/tmp' )); $value = "MECARD:N:XXXXX;ADR:xxx xxxxx xxxxxx xx xxx city;" . "TEL:+XXXXXXXXX;EMAIL:xxxxx@gmail.com;;"; //$qrcode->render($value); $qrcode->renderBase64Dom($value, "logo.png", 0.7);
示例
变更日志
v1.0.0
- 首次发布
v1.0.1
- Base64编码
- 存储图像
v1.1.0
- 标志附加
- 支持像库一样,不仅仅适用于Laravel。