81

qrdecode

qrdecode
SYNOPSIS

qrdecode($qr, $type='file', $imagick=false)

DESCRIPTION

qrdecode returns the character string read in an image which contains a QR code. If $type is 'file', $qr is the path name of a file of an image. If $type is 'blob', $qr is an image in its binary format. If $type is 'resource', $qr is a resource of an image. If imagick is true and if the extension imagick is installed, ImageMagick is used to read the content of $qr. qrdecode returns false if a QR code could not be read in $qr.

CODE
  1. require_once 'vendor/autoload.php';
  2.  
  3. use zxing\QrReader;
  4.  
  5. function qrdecode($qr, $type='file', $imagick=false) {
  6.     if (!$qr or !$type or !in_array($type, array('file', 'blob', 'resource'))) {
  7.         return false;
  8.     }
  9.    
  10.     $qrcode = new Zxing\QrReader($qr, $type, $imagick);
  11.  
  12.     return $qrcode !== false ? $qrcode->text() : false;
  13. }

IMPORTANT: Install QR code decoder / reader for PHP, a port from the ZXing library, at the root of the website:

$ composer require zxing/qr-reader
EXAMPLE
$ php -a
php > require_once 'library/qrdecode.php';
php > echo qrdecode('qr.png', 'file');
php > echo qrdecode(file_get_contents('qr.png'), 'blob');
php > echo qrdecode(imagecreatefrompng('qr.png'), 'resource');
SEE ALSO

qrencode

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].