Skip to content

lasalesi/phpqrcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phpqrcode

PHP library to produce QR Codes

This is PHP implementation of QR Code 2-D barcode generator. It is pure-php LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.

It is tested to work with a standard Debian 9 (stretch), php7.0 and apache2.

Licensing

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file) for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Requirements

  • PHP7.0
  • PHP GD2 extension with JPEG and PNG support

Installation

If you want to recreate cache by yourself make sure cache directory is writable and you have permisions to write into it. Also make sure you are able to read files in it if you have cache option enabled

Configuration

Feel free to modify config constants in qrconfig.php file. Read about it in provided comments and project wiki page (links in README file)

Quick start

Refer to the /samples section to get a quick start

Very simple QR code

<?php
  //include only that one, rest required files will be included from it
  require_once("qrlib.php");
  
  QRcode::png('PHP QR Code :)');

Hardcoded QR code with settings, output to browser

WARNING! it should be FIRST and ONLY output generated by script, otherwise rest of output will land inside PNG binary, breaking it for sure

<?php
  //include only that one, rest required files will be included from it
  require_once("qrlib.php");
  
  //write code into file, Error corection lecer is lowest, L (one form: L,M,Q,H)
  //each code square will be 4x4 pixels (4x zoom)
  //code will have 2 code squares white boundary around 
  
  QRcode::png('PHP QR Code :)', 'test.png', 'L', 4, 2);

Show benchmark

QRtools::timeBenchmark();

Rebuild cache

QRtools::buildCache();

Code generated in text mode - as a binary table

$tab = $qr->encode('Test content');
QRspec::debug($tab, true);

TCPDF integration

Inside bindings/tcpdf you will find slightly modified 2dbarcodes.php. Instal phpqrcode liblaty inside tcpdf folder, then overwrite (or merge) 2dbarcodes.php

Then use similar as example #50 from TCPDF examples:

<?php

$style = array(
    'border' => true,
    'padding' => 4,
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, //array(255,255,255)
);

//code name: QR, specify error correction level after semicolon (L,M,Q,H)
$pdf->write2DBarcode('PHP QR Code :)', 'QR,L', '', '', 30, 30, $style, 'N');

Troubleshooting

Uncaught Error: Call to undefined function ImageCreate()

In case this error appears (e.g. in /var/log/apache2/error.log once calling simple_qr.php), the GD library is not ready. Install it

$ sudo apt update && sudo apt install php-gd
$ sudo service apache2 restart

Acknowledgements

This project is based on the work of Dominik Dzienia on http://phpqrcode.sourceforge.net/

Based on C libqrencode library (ver. 3.1.1), Copyright (C) 2006-2010 by Kentaro Fukuchi, http://megaui.net/fukuchi/works/qrencode/index.en.html

QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other countries.

Reed-Solomon code encoder is written by Phil Karn, KA9Q. Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q

About

PHP library to produce QR Codes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages