README
This is a PHP library to detect and decode QR-codes.
This is first and only QR code reader that works without extensions.
Ported from ZXing library
Installation
The recommended method of installing this library is via Composer.
Run the following command from your project root:
$ composer require khanamiryan/qrcode-detector-decoder
Usage
require __DIR__ . "/vendor/autoload.php";
use Zxing\QrReader;
$qrcode = new QrReader('path/to_image');
$text = $qrcode->text(); //return decoded text from QR Code
Requirements
Contributing
You can help the project by adding features, cleaning the code, adding composer and other.
- Fork it
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
- Packages
- Collections
- Login
Simple PHP QR Code Reader / Decoder
PHP QR Code Reader / Decoder
This is a PHP library to detect and decode QR-codes.
This is QR code reader that works without extensions.
This library supports PSR-4.
Based on QR code decoder / reader for PHP
Ported
from ZXing library
Installation
Use Composer:
composer require libern/qr-code-reader
Usage
From image url
$QRCodeReader = new Libern\QRCodeReader\QRCodeReader();
$qrcode_text = $QRCodeReader->decode("path_to_qr_code");
echo $qrcode_text;
From image stream
$QRCodeReader = new Libern\QRCodeReader\QRCodeReader();
$qrcode_text = $QRCodeReader->decode(base64_encode("image_stream"));
echo $qrcode_text;
Requirements
Author
libern
In this article i will show how to process QR codes in PHP and how to generate QR code images and scan those images back to their original text.
Overview
QR codes is a standard that represents some decoded text often used with commercial items such as products and it used to identify those items in graphical format in the form of images. There are a lot of software that can generate and scan QR codes and in this tutorial we
will show you how to manipulate QR codes with PHP.
For the purpose of this tutorial we will use two libraries that can be used to generate and scan QR codes, which are:
- phpqrcode: we will use this to generate QR codes, you can download it from this link.
- php-qrcode-detector-decoder: we will use to scan QR codes install it from this
link.
After downloading the two libraries add them to your project, in the next sections we will see how to generate QR codes.
Generating QR codes:
To generate QR codes you need first to include the qrlib.php in your project, next create a new file generate.php as shown below:
Output QR codes to the browser:
To output QR codes
to the browser directly call Qrcode::png() as shown:
Now run your script in the browser, and check the image shown.
Passing the output to img src:
Instead of outputting the result directly into the browser you can use the it as the src of the img tag as shown here:
Output QR code according to parameter:
You can pass parameters to the url therapy you can capture those parameters and output QR codes accordingly as shown below:
Also you
can pass parameters to url in the img src:
Saving the Qr code to a file:
You can if you want to save the QR code to file or store it in the database, just pass a second parameter to QRcode::png() which is the file path to store in the png as shown here:
include './phpqrcode/qrlib.php';
$code = "web mob tuts";
$fileName = md5(uniqid()).'.png';
$tempDir = "files"; // the directory to store the files
$filePath = $tempDir . "/" . $fileName;
QRcode::png($code, $filePath); // note the second parameter
if(file_exists($filePath)) {
echo '';
}
Controlling pixel size:
You can control the pixel size when creating the QR code by passing a third and fourth parameters, the third parameter represents the ECC level and the fourth
parameter represents the pixel size, 1 small size and 4 biggest size:
$code = 'web mob tuts';
QRcode::png($code, 'files/1.png', QR_ECLEVEL_L, 1);
QRcode::png($code, 'files/2.png', QR_ECLEVEL_M, 2);
QRcode::png($code, 'files/3.png', QR_ECLEVEL_Q, 3);
QRcode::png($code, 'files/4.png', QR_ECLEVEL_H, 4);
// displaying
echo '';
echo '';
echo '';
echo '';
Reading QR codes:
To read or scan Qr code we will use the second library, so include the dependencies from the vendor autoload file as follows:
As shown above we included the vendor composer file and then we imported the namespace relating the class QrReader, not that without this line you will get a fatal error.
To read specific Qr codes just pass the image png file to read method
as shown below:
$qrcode = new QrReader('files/1.png');
$text = $qrcode->text();
echo $text;
Calling $qrcode->text() will retrieve the QR code data.
3.7 21 votes
Article Rating
What's your reaction?
How do I decrypt a QR code?
How to decode QR codes without scanning them.
Install QRreader from the Chrome Store..
When you see a QR code on a Web page, just right-click it and select "Read QR code from image" from the context menu. Step 2: Right-click the QR code. ... .
If the code just contains a link, a new tab will open with that link..
How QR code is implemented in PHP?
Let's create a QR code in PHP.
Install dependencies. ... .
Write the code. ... .
Test that the code works. ... .
Create a QR code with a logo. ... .
This code extends the base QROptions class, allowing it to set a width and height around the image which is overlaid on the QR code. ... .
Update the code. ... .
Add an image file..
How do I read a QR code?
You can use the basic camera app to scan QR codes on most Android devices..
Open your Android device's camera app..
Move your camera so the QR code is in the frame. ... .
Open Lens and move your camera so the QR code is in the frame..
The QR code's URL will appear over it..
Can you get data from QR code?
That's right, QR codes are more than a convenient way to pull up a URL, they actually are able to transmit personal data like a phone number or email address, along with how often the user might be scanning the code in question.