url 生成二维码图片
介绍
简单的QrCode是一个易于使用的包装,适用于流行的Laravel框架,基于Bacon / BaconQrCode提供的出色工作。我们为Laravel用户创建了一个熟悉且易于安装的界面。
翻译
我们正在寻找使用阿拉伯语,西班牙语,法语,韩语或日语的用户来帮助翻译此文档。如果您能够翻译,请创建拉取请求!
首先,将Simple QrCode包添加到您require的composer.json文件中:
"require": {
"simplesoftwareio/simple-qrcode": "~2"
}
接下来,运行该composer update命令。
服务提供者
Laravel <= 5.4
注册在您config/app.php的内providers阵列。
SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class
别名
Laravel <= 5.4
最后,在数组中的config/app.php配置文件中注册aliases。
'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
用法
基本用法
使用QrCode Generator非常简单。最基本的语法是:
QrCode::generate('Make me into a QrCode!');
这将使一个QrCode说“让我成为一个QrCode!”
生成
Generate 用于制作QrCode。
QrCode::generate('Make me into a QrCode!');
当心!如果在链中使用,则必须最后调用此方法。
该generate方法有第二个参数,它将接受保存QrCode的文件名和路径。
QrCode::generate('Make me into a QrCode!', '../public/qrcodes/qrcode.svg');
格式更改
QrCode Generator设置为默认返回SVG图像。
小心!该format方法必须在任何其他格式选项如被称为size,color,backgroundColor,和margin。
目前支持三种格式; PNG,EPS和SVG。要更改格式,请使用以下代码:
QrCode::format('png'); //Will return a PNG image
QrCode::format('eps'); //Will return a EPS image
QrCode::format('svg'); //Will return a SVG image
尺寸变化
QrCode Generator默认返回可能的最小尺寸(以像素为单位)来创建QrCode。
您可以使用该size方法更改QrCode的大小。只需使用以下语法指定所需的大小(以像素为单位):
QrCode::size(100);
颜色变化
更改QrCode的颜色时要小心。有些读者在阅读彩色QrCodes时非常困难。
所有颜色必须以RGB(红绿蓝)表示。您可以使用以下命令更改QrCode的颜色:
QrCode::color(255,0,255);
还支持背景颜色变化并以相同方式表达。
QrCode::backgroundColor(255,255,0);
保证金变更
还支持更改QrCode周围边距的功能。只需使用以下语法指定所需的边距:
QrCode::margin(100);
错误修正
更改纠错级别很容易。只需使用以下语法:
QrCode::errorCorrection('H');
以下是该errorCorrection方法的受支持选项。
错误修正 提供保证
大号 可以恢复7%的代码字。
中号 可以恢复15%的代码字。
Q 可以恢复25%的代码字。
H 可以恢复30%的代码字。
使用的纠错越多; QrCode变得越大,它可以存储的数据越少。阅读有关纠错的更多信息。
编码
更改用于构建QrCode的字符编码。默认情况下ISO-8859-1被选为编码器。阅读有关字符编码的更多信息您可以将其更改为以下任何一项:
QrCode::encoding('UTF-8')->generate('Make me a QrCode with special symbols ♠♥!!');
字符编码器
ISO-8859-1
ISO-8859-2
ISO-8859-3
ISO-8859-4
ISO-8859-5
ISO-8859-6
ISO-8859-7
ISO-8859-8
ISO-8859-9
ISO-8859-10
ISO-8859-11
ISO-8859-12
ISO-8859-13
ISO-8859-14
ISO-8859-15
ISO-8859-16
SHIFT-JIS
WINDOWS-1250
WINDOWS-1251
WINDOWS-1252
WINDOWS-1256
UTF-16BE
UTF-8
ASCII
GBK
EUC-KR
错误Could not encode content to ISO-8859-1意味着正在使用错误的字符编码类型。UTF-8如果您不确定,我们建议您。
合并
该merge方法通过QrCode合并图像。这通常用于在QrCode中放置徽标。
QrCode::merge($filename, $percentage, $absolute);
//Generates a QrCode with an image centered in the middle.
QrCode::format('png')->merge('path-to-image.png')->generate();
//Generates a QrCode with an image centered in the middle. The inserted image takes up 30% of the QrCode.
QrCode::format('png')->merge('path-to-image.png', .3)->generate();
//Generates a QrCode with an image centered in the middle. The inserted image takes up 30% of the QrCode.
QrCode::format('png')->merge('http://www.google.com/someimage.png', .3, true)->generate();
该merge方法目前仅支持PNG。如果$absolute设置为,则文件路径相对于应用程序基本路径false。将此变量更改true为使用绝对路径。
在使用该merge方法时,您应该使用高级别的错误纠正,以确保QrCode仍然可读。我们建议使用errorCorrection('H')。
合并徽标
合并二进制字符串
该mergeString方法可用于实现与merge调用相同的方法,但它允许您提供文件的字符串表示而不是文件路径。这在使用Storage立面时很有用。它的界面非常类似于merge通话。
QrCode::mergeString(Storage::get('path/to/image.png'), $percentage);
//Generates a QrCode with an image centered in the middle.
QrCode::format('png')->mergeString(Storage::get('path/to/image.png'))->generate();
//Generates a QrCode with an image centered in the middle. The inserted image takes up 30% of the QrCode.
QrCode::format('png')->mergeString(Storage::get('path/to/image.png'), .3)->generate();
与普通merge呼叫一样,此时仅支持PNG。这同样适用于纠错,建议使用高电平。
助手
什么是帮手?
帮助程序是一种创建QrCodes的简便方法,可以使读者在扫描时执行某个操作。
比特币
这个助手生成一个可扫描的比特币来发送付款。更多信息
QrCode::BTC($address, $amount);
//Sends a 0.334BTC payment to the address
QrCode::BTC('bitcoin address', 0.334);
//Sends a 0.334BTC payment to the address with some optional arguments
QrCode::size(500)->BTC('address', 0.0034, [
'label' => 'my label',
'message' => 'my message',
'returnAddress' => 'https://www.returnaddress.com'
]);
电子邮件
此助手生成一个电子邮件qrcode,可以填写电子邮件地址,主题和正文。
QrCode::email($to, $subject, $body);
//Fills in the to address
QrCode::email('foo@bar.com');
//Fills in the to address, subject, and body of an e-mail.
QrCode::email('foo@bar.com', 'This is the subject.', 'This is the message body.');
//Fills in just the subject and body of an e-mail.
QrCode::email(null, 'This is the subject.', 'This is the message body.');
地理
此帮助程序生成手机可以读取的纬度和经度,并在Google地图或类似应用程序中打开该位置。
QrCode::geo($latitude, $longitude);
QrCode::geo(37.822214, -122.481769);
电话号码
该助手生成一个可以扫描的QrCode,然后拨打一个号码。
QrCode::phoneNumber($phoneNumber);
QrCode::phoneNumber('555-555-5555');
QrCode::phoneNumber('1-800-Laravel');
短信(短信)
该帮助程序生成可以使用发送到地址和消息正文预填充的SMS消息。
QrCode::SMS($phoneNumber, $message);
//Creates a text message with the number filled in.
QrCode::SMS('555-555-5555');
//Creates a text message with the number and message filled in.
QrCode::SMS('555-555-5555', 'Body of the message');
无线上网
这个助手可以制作可扫描的QrCodes,可以将手机连接到WiFI网络。
QrCode::wiFi([
'encryption' => 'WPA/WEP',
'ssid' => 'SSID of the network',
'password' => 'Password of the network',
'hidden' => 'Whether the network is a hidden SSID or not.'
]);
//Connects to an open WiFi network.
QrCode::wiFi([
'ssid' => 'Network Name',
]);
//Connects to an open, hidden WiFi network.
QrCode::wiFi([
'ssid' => 'Network Name',
'hidden' => 'true'
]);
//Connects to an secured, WiFi network.
QrCode::wiFi([
'ssid' => 'Network Name',
'encryption' => 'WPA',
'password' => 'myPassword'
]);
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: