This article mainly introduces the Laravel generation of two-dimensional code of the method, has a certain reference value, now share to everyone, the need for friends can refer to
(This example laravel version >=5.6, PHP version >=7.0)
1. First, add the QRCode package to your composer.json
file require
:
"Require": { "Simplesoftwareio/simple-qrcode": "~"}
Then, run composer update
.
2. Basic use
It is very convenient to use QRCode generator. In most cases this is the case:
Qrcode::generate (' Make me into a qrcode! ');
This allows you to create a scan that shows what the "Make me into a qrcode!" QR code is.
3. Self-defined output image format
QRCode Generator A picture of the default output SVG format.
Attention! The format
method must be set first, other settings such as:,,, size
color
backgroundColor
and margin
the settings must be behind it.
Support Png,eps,svg three formats, set up in the following ways:
Qrcode::format (' png '); Would return a PNG imageqrcode::format (' EPs '); Would return a EPS imageqrcode::format (' svg '); Would return a SVG image
4. Size setting
The QRCode Generator returns a QR code that may be the smallest pixel unit by default.
You can use size
the method to set its size. Below is an example of setting the pixel size:
Qrcode::size (100);
5. Color setting
Note that changing the color may cause some devices to be difficult to identify.
The format of the color settings must be in RBG format. Here's how it's set up:
Qrcode::color (255,0,255);
The same method is used to set the background color:
Qrcode::backgroundcolor (255,255,0);
6. Margin settings
Setting margins is also supported. Here's how it's set up:
Qrcode::margin (100);
7, add logo map
merge
The QRCode method allows you to add a logo image to the generated results. Below is a common use of the logo image for two-dimensional code plus.
Qrcode::merge ($filename, $percentage, $absolute); Generate a logo image in the middle of the QR Code qrcode::format (' PNG ')->merge (' Path-to-image.png ')->generate (); Create a logo image in the middle of the two-dimensional code, and logo images of the entire QR code image 30%. Qrcode::format (' png ')->merge (' Path-to-image.png ',. 3)->generate (); Use absolute path logo image address to create two-dimensional code, logo image of the entire QR code image 30%. Qrcode::format (' png ')->merge (' Http://www.google.com/someimage.png ',. 3, True)->generate ();
merge
Method currently supports only PNG-formatted pictures by default with the application's root path, the third parameter is set to be true
able to switch to using absolute path
Here is a complete small demo:
/** * @param int $size This parameter is the dimension of the QR code, is the pixel value * @param string $info This parameter is the content of the QR code, the content is text, the scan is displayed this text; * The URL that starts with http://or https://opens this URL * @return mixed * * /public static function Createqrcode ($size, $ Info) { $size = $size?: $info = $info?: "Success"; $res = Qrcode::size ($size)->color (50,255,100)->generate ($info); return $res; }
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!