Producing dynamic QR code and put it aside as a “PNG” picture is a crucial job for any developer. QR codes are taking part in vital function in lots of industries like ecommerce, ticket reserving, on-line cost or virtually all over the place today!.
QR codes (Fast Response Codes) are two-dimensional barcodes. It’s a visible label with details about the merchandise that may be readable by scanning machines. you’ll be able to connected to the merchandise. QR Code appears to be like like a black squares grid on a white background. Please refer under picture:
Producing dynamic QR code utilizing php
On this article, I’ll clarify you all of the steps about how one can generate dynamic QR code utilizing php. I just lately had a requirement to generate a QR code for occasion ticket and create a PDF with the QR code.
Urged Learn: How to Generate PDF from Mysql Database using PHP
There are numerous third-party libraries accessible for producing QR codes in PHP. I selected the PHP QR Code library. As a result of use of this library could be very straightforward and ideal match for my necessities.
I’m going to share the code on this tutorial step-by-step.
Obtain Library:
Obtain the PHP QR library utilizing the under hyperlink.
https://sourceforge.net/projects/phpqrcode/files/
After obtain, please extract the zip file. I created a folder named qrcode within the challenge folder and moved the extracted folder inside it.
Generate QR Code And Show In Browser:
Please discover under The syntax for producing QR codes.
QRcode::png($textual content, $file, $ecc, $pixel_size, $frame_size);
QRcode::png($textual content, $file, $ecc, $pixel_size, $frame_size);
|
- $textual content => Obligatory parameter. Different parameters are elective. This parameters can be use to generate the QR code and retailer the data.
- $file => Location of the file to avoid wasting the generated QR code.
- $ecc => Error correction functionality of QR. Following values are used. L, M, Q, and H.
- $pixel_size => Pixel dimension of the QR code.
- $frame_size => Measurement of QR code. Values are used from 0 to 10.
Generate QR Code
Create a brand new PHP file named qr_generator.php contained in the qrcode folder and paste the under code to generate QR code within the browser.
<?php
require_once(“phpqrcode/qrlib.php”);
$merchandise = “ID 23456”;
QRcode::png($merchandise);
?>
<?php require_once(“phpqrcode/qrlib.php”); $merchandise = “ID 23456”; QRcode::png($merchandise); ?>
|
The $textual content is a parameter that could be your merchandise id, order id or merchandise data.
Save QR Code As Picture:
Now I’ll create a from to enter the data and generate QR code in addition to save the QR code as a picture. I must outline the file location the place QR code picture will retailer. Use the under code to generate QR and put it aside as a png picture.
<div class=”content material”>
<div class=”col-lg-12″>
<div class=”panel panel-primary”>
<div class=”panel-heading”>Enter data to generate QR Code</div>
<div class=”panel-body”>
<div class=”input_field_wrapper”>
<div>
<kind methodology=”publish”>
<enter kind=”textual content” identify=”item_id” worth=”” required />
<enter kind=”submit” class=” btn btn-primary” worth=”Generate QR Code” type=” margin:5px;”>
</kind>
</div>
</div>
</div></div></div>
<div class=”col-lg-12″>
<?php
//load the ar library
embrace ‘phpqrcode/qrlib.php’;
if(isset($_POST[‘item_id’]))
//information to be saved in qr
$merchandise =$_POST[‘item_id’];
//file path
$file = “photographs/qr1.png”;
//different parameters
$ecc=”H”;
$pixel_size = 20;
$frame_size = 5;
// Generates QR Code and Save as PNG
QRcode::png($merchandise, $file, $ecc, $pixel_size, $frame_size);
// Displaying the saved QR code if you would like
echo “<div><h3>Generated QR Code for “.$merchandise.” </h3><br><img src=””.$file.”” width=”150″></div>”;
?>
</div>
</div>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<div class=“content material”> <div class=“col-lg-12”> <div class=“panel panel-primary”> <div class=“panel-heading”>Enter data to generate QR Code</div> <div class=“panel-body”> <div class=“input_field_wrapper”> <div> <kind methodology=“publish”> <enter kind=“textual content” identify=“item_id” worth=“” required /> <enter kind=“submit” class=” btn btn-primary” worth=“Generate QR Code” type=” margin:5px;”> </kind> </div> </div> </div></div></div> <div class=“col-lg-12”> <?php
//load the ar library embrace ‘phpqrcode/qrlib.php’; if(isset($_POST[‘item_id’])) //information to be saved in qr $merchandise =$_POST[‘item_id’];
//file path $file = “photographs/qr1.png”;
//different parameters $ecc = ‘H’; $pixel_size = 20; $frame_size = 5;
// Generates QR Code and Save as PNG QRcode::png($merchandise, $file, $ecc, $pixel_size, $frame_size);
// Displaying the saved QR code if you would like echo “<div><h3>Generated QR Code for “.$merchandise.” </h3><br><img src=””.$file.“” width=”150″></div>”;
?> </div>
</div>
|
Now open your file in browser: http://loclhost:8080/qrcode/qr_generator.php
Notice: Please verify permission to the “photographs” folder why as a result of mac by default don’t permit to avoid wasting the information.
Are you need to get implementation assist, or modify or lengthen the performance of this script?
A Tutorialswebsite Skilled can do it for you.
Wrapping Phrases!
Thanks for studying 🙏, I hope you discovered The right way to generate dynamic QR code in PHP tutorial useful in your challenge. Continue learning!. If you happen to face any drawback – I’m right here to unravel your issues.
Additionally Learn: How to Create ZIP File using PHP
Cyber Freaks is the Skilled Net Developer and Founding father of “Tutorialswebsite”. He lives in Delhi and likes to be a self dependent particular person. As an writer, he’s making an attempt his greatest to enhance this platform day-to-day. His ardour, dedication and fast determination making capability to face aside from others. He’s an avid blogger and writes on the publications like Dzone, e27.co