PHP generation, identification of QR code

Source: Internet
Author: User
Tags eol imagemagick vcard

Warm tip: After this 2 days of tossing, I uninstalled the php7.1. There's only one reason--I want to install the barcode Extension Module Php-zbarcode C language source code does not support PHP7. Changed the source code for half a day, or did not work. Finally look at GitHub on a warm issue back to the php5.6. It's a lot easier to pack up ~ words not to say, the starting point.

First, PHP generated QR code two-dimensional code

Phpqrcode is a third-party package written by PHP that can generate QR code codes. The official website has many examples to refer to, the use is very simple, 2 lines of code.

<?php//1. Use the official website package require './phpqrcode/qrlib.php '; QRCode::p ng (' http://github.com ', ' qrcode.png ', qr_eclevel_l, 8, 4, false);//The last parameter of the method has a bug, write TRUE (save and print) does not print the display, Need to modify the source//QRCode::p ng (' 123 ', './qrcode.png ', qr_eclevel_l, 4, 4, TRUE);//2. Use composer Package//Aferrandini/phpqrcode This package is ranked first on the packagist.org, is based on the official website packaging, but the bug seems to be good there ~ ~. Other similar composer bags have a lot of, according to demand for it ~ ~

Second, jquery generated qrcode QR code

Jquery.qrcode.js is a plug-in library that generates QR code two-dimensional code on the front. Here is what I wrote on the jquery.qrcode.js in the GitHub warehouse on the previous example. Look at the code.

<! DOCTYPE html>

Then the browser accesses this page and sees 4 QR codes.

Note:

    1. In short, now when you write down this document, according to the official website and GitHub and some other blog notes are loaded only jquery.qrcode.js (except Query.js), but only to load this jQ I do not work here, must reload Qrcode.js
    2. The code for the JQ generation of QR code must be behind the container element and can be placed inside the <body> tag. If you put it in the

Third, PHP generated Electronic Business Card 1. VCard

VCard is the file format standard for Electronic business cards. It is usually attached to e-mail, but it can also be used for other occasions (such as exchanging with each other on the Internet). The VCard can contain information such as: name, address information, telephone number, Url,logo, photo, etc. (from Wikipedia).

2. Examples

Below is a vcard with personal information (excerpted from Wikipedia), which can be modified by reference to:

Begin:vcardversion:2.1n:gump; Forrestfn:forrest gumporg:gump Shrimp Co.TITLE:Shrimp Mantel; work; VOICE: (111) 555-1212tel; HOME; VOICE: (404) 555-1212adr; work:;; Waters Edge; Baytown; la;30314; States of Americalabel; work; encoding=quoted-printable:100 Waters Edge=0d=0abaytown, LA 30314=0d=0aunited states of Americaadr; HOME:;; Plantation St.; Baytown; la;30314; States of Americalabel; HOME; Encoding=quoted-printable:42 Plantation St.=0d=0abaytown, LA 30314=0d=0aunited states of AmericaEMAIL; Pref;internet:[email Protected]rev:20080424t195243zend:vcard

Refer to the VCard example above to make a personal electronic Business card. Specific field interpretation can refer to the introduction of the VCard on the Baidu Encyclopedia.

3. PHP generates Electronic Business cards

Write one, using the Phpqrcode package to generate my vcard:

<?php//using Phpqrcode to generate Electronic business cards require './phpqrcode/qrlib.php '; $vcard = <<<EOLBEGIN:VCARDVERSION:2.1N:Jin; MingcFN:mingcORG:free Mantitle:phpertel; work; Voice:1382173xxxxtel; HOME; Voice:1383284xxxxadr; work; Tianjin, Chinalabel; work; Encoding=quoted-printable:tianjin, China (LABEL; Work) ADR; HOME; Tianjin, Chinalabel; HOME; Encoding=quoted-printable:tianjin, China (LABEL; HOME) EMAIL; pref;internet:[email protected]rev:20171201t005548zend:vcardeol; QRCode::p ng ($vcard);//define (' EOL ', "\ r \ n");//$vcard = ' begin:vcard '. eol;//$vcard. = ' version:2.1 '. eol;//$vcard. = ' N:JIN;MINGC '. eol;//$vcard. = ' FN:MINGC '. eol;//$vcard. = ' Org:free man '. eol;//$vcard. = ' Title:phper '. eol;//$vcard. = ' TEL; work; Voice:1382173xxxx '. eol;//$vcard. = ' TEL; HOME; Voice:1383284xxxx '. eol;//$vcard. = ' ADR; work; Tianjin, China '. eol;//$vcard. = ' LABEL; work; Encoding=quoted-printable:tianjin, China (LABEL; Work) '. eol;//$vcard. = ' ADR; HOME; Tianjin, China '. eol;//$vcard. = ' LABEL; HOME; Encoding=quoted-printable:tianjin, CHina (LABEL; HOME) '. eol;//$vcard. = ' EMAIL; Pref;internet:[email protected] '. eol;//$vcard. = ' rev:20171201t005548z '. eol;//$vcard. = ' End:vcard ';//QRCode::p ng ($vcard);

Browser Access this PHP script will display a QR code, sweep, the result is as follows:

This vcard can also be added directly to your phone's contacts.

Iv. PHP identification QR code (tool)

PHP requires 3 tools to identify a QR code or barcode.

1. ImageMagick

ImageMagick is an open source software suite for viewing, editing bitmap files, and converting image formats. It can read and edit more than 100 image formats. ImageMagick is issued with a ImageMagick license (a BSD-like license).

2. Zbar

Zbar is an open source software suite for reading barcodes from a variety of sources, such as video streaming, image files and raw strength sensors. It supports a variety of popular barcodes including Ean-13/upc-a,upc-e,ean-8,code 128,code 39,interleaved 2 of 5 and QR code.

3. Php-zbarcode

Php-zbarcode is a PHP extension module that reads barcodes. You will also need to install both the ImageMagick and Zbar command-line suites before using this module.

Phpzbarcode relies on the ImageMagick and Zbar,zbar to rely on the JPEG library to provide JPEG image support, so install JPEG support first.

Installing the JPEG Library

: http://www.imagemagick.org/download/delegates/, the package I downloaded is named jpegsrc.v9b.tar.gz .

wget Http://www.imagemagick.org/download/delegates/jpegsrc.v9b.tar.gztar XF JPEGSRC.V9B.TAR.GZCD jpeg-9b/makesudo Make install

V. Installation of ImageMagick

: https://www.imagemagick.org/download/, the package I downloaded is named ImageMagick.tar.gz .

wget Https://www.imagemagick.org/download/ImageMagick.tar.gztar XF IMAGEMAGICK.TAR.GZCD imagemagick-7.0.7-13./ Configuresudo Makesudo make Installsudo ldconfig/usr/local/libmagick--version

Common error *******************************************

Error 1: Loading the dynamic link library error when installing the relevant command magick , convert , etc.

Convert:error while loading shared libraries:libmagickcore-7.q16hdri.so.4:cannot open Shared object file:no such file or directory

Workaround: Dynamically load dynamic-link libraries

sudo ldconfig/usr/local/lib

You can then use the command-line interface normally.

Vi. installation of Zbar

: https://sourceforge.net/projects/zbar/files/zbar/. I downloaded the latest version of 0.10, with the package named zbar-0.10.tar.gz .

Tar XF zbar-0.10.tar.gzcd zbar-0.10/sudo ln-s/usr/local/include/imagemagick-7/usr/local/include/imagemagicksudo LN- S/usr/local/include/imagemagick-7/magickwand/usr/local/include/wand./configure--disable-video--WITHOUT-GTK-- WITHOUT-QT--without-python Makemakesudo make installzbarimg--version

Common error ********************************************

Error 1: MagickWand.h header File not found

ImageMagick package found but wand/magickwand.h not installed?! -this is a problem with your ImageMagick install,-please resolve the inconsistency and try again ...

Workaround: Zbar configuration file./configure will not find MagickWand.h at run time, it is in the/usr/local/include/imagemagick-7/magickwand directory, but./configure Execution will go to the wand/directory (not found), so need to do two soft connections so that./configure can find the MagickWand.h file

sudo ln-s/usr/local/include/imagemagick-7/usr/local/include/imagemagicksudo ln-s/usr/local/include/imagemagick-7 /magickwand/usr/local/include/wand

Error 2:make multiple warning and error during compilation

zbar/decoder/ean.c:in function ' Ean_part_end4 ': zbar/decoder/ean.c:245:13:warning:logical not be only applied to the LEF T hand side of comparison [-wlogical-not-parentheses] if (!par = fwd) {^~zbar/decoder/ean.c:245:8: note: Add parentheses around left hand side expression to silence this warning if (!par = fwd) {^~~~ () Zba r/decoder/ean.c:in function ' Ean_part_end7 ': zbar/decoder/ean.c:294:13:warning:logical not be only applied to the left H  and side of comparison [-wlogical-not-parentheses] if (!par = = fwd) {^~zbar/decoder/ean.c:294:8: Note:add Parentheses around left hand side expression to silence this warning if (!par = fwd) {^~~~ () zbar/q rcode/qrdec.c:in function ' Qr_finder_quick_crossing_check ': zbar/qrcode/qrdec.c:1215:27:warning:logical not are only Applied to the left hand side of comparison [-wlogical-not-parentheses] if (!_img[_y0*_width+_x0]!=_v| |!           _IMG[_Y1*_WIDTH+_X1]!=_V) return 1;                ^~zbar/qrcode/qrdec.c:1215:6: Note:add parentheses around left hand side expression to silence this Warni ng if (!_img[_y0*_width+_x0]!=_v| |!      _IMG[_Y1*_WIDTH+_X1]!=_V) return 1; ^~~~~~~~~~~~~~~~~~~~~ () zbar/qrcode/qrdec.c:1215:54:warning:logical not be only applied to the Left hand side of comparison [-wlogical-not-parentheses] if (!_img[_y0*_width+_x0]!=_v| |!                                                      _IMG[_Y1*_WIDTH+_X1]!=_V) return 1; ^~zbar/qrcode/qrdec.c:1215:33:note:add parentheses around left hand side expression to silence this warning if (!_img[_ y0*_width+_x0]!=_v| |!                                 _IMG[_Y1*_WIDTH+_X1]!=_V) return 1; ^~~~~~~~~~~~~~~~~~~~~ () zbar/qrcode/qrdec.c:1216:45:warning:logical Not was only applied to the left hand side of comparison [-wlogical-not-parentheses] if (!_img[(_y0+_y1>>1) *_width+ (               _x0+_x1>>1)]==_v) return-1;                              ^~zbar/qrcode/qrdec.c:1216:6: Note:add parentheses around left hand side expression to Sile      NCE this warning if (!_img[(_y0+_y1>>1) *_width+ (_x0+_x1>>1)]==_v) return-1; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ () zbar/qrcode/qrdec.c:in function ' Qr_ Finder_locate_crossing ': zbar/qrcode/qrdec.c:1257:33:warning:logical not be only applied to the left hand side of Compari                                 son [-wlogical-not-parentheses] if (!_img[x0[1]*_width+x0[0]]!=_v) break; ^~zbar/qrcode/qrdec.c:1257:8: Note:add parentheses around left hand side expression to silence this warning if (!_img[        X0[1]*_WIDTH+X0[0]]!=_V) break; ^~~~~~~~~~~~~~~~~~~~~~~~~ () zbar/qrcode/qrdec.c:1269:33:warning:logical not be only appli                                 Ed to the left hand side of comparison [-wlogical-not-parentheses] if (!_img[x1[1]*_width+x1[0]]!=_v) break; ^~zbar/Qrcode/qrdec.c:1269:8: Note:add parentheses around left hand side expression to silence this warning if (!_img[x1[1]*_        WIDTH+X1[0]]!=_V) break; ^~~~~~~~~~~~~~~~~~~~~~~~~ () zbar/jpeg.c:in function ' _zbar_convert_jpeg_to_y ': zbar/jpeg.c: 174:39:warning:assignment from incompatible pointer type [-wincompatible-pointer-types] Cinfo->src->fill_i                                       Nput_buffer = Fill_input_buffer; ^

Workaround: Compile again

Make

Vii. installation of Php-zbarcode

: Https://github.com/mkoppanen/php-zbarcode

wget https://github.com/mkoppanen/php-zbarcode/archive/master.zipunzip master.zipcd php-zbarcode-master/. Configure--with-php-config=/usr/bin/php-configmakesudo make Install

You will be prompted to install the module directory after success

[Email protected]:~/downloads/qrcode/php-zbarcode-master$ sudo make install installing shared extensions:     /usr/ lib/php/20131226/

Confirm the location of the module

[Email protected]:~/downloads/qrcode/php-zbarcode-master$ ls/usr/lib/php/20131226/build        dom.so       gettext.so   mcrypt.so     mysqli.so   pdo_mysql.so   posix.so      sockets.so  tokenizer.so  xmlwriter.sobz2.so       exif.so      iconv.so     memcached.so  mysqlnd.so  pdo_odbc.so    readline.so   sqlite3.so  wddx.so       xsl.socalendar.so  fileinfo.so  igbinary.so  memcache.so   mysql.so    pdo.so         redis.so      sysvmsg.so  xmlreader.so  zbarcode.soctype.so     ftp.so       json.so      mongo.so      odbc.so     pdo_sqlite.so  shmop.so      sysvsem.so  xmlrpc.so     zip.sodba.so       gd.so        mbstring.so  msgpack.so    opcache.so  phar.so        simplexml.so  sysvshm.so  xml.so

You can see that the zbarcode.so file is available.

Enable Zbarcode extension, edit php.ini file

sudo vim/etc/php/5.6/apache2/php.ini

Add a row last

Extension=zbarcode.ini

Restart Apache

Sudo/etc/init.d/apache2 restart

This is good, you can use the barcode extension.

Note The PHP-M command shows the extension enabled by PHP-CLI mode, and the php.ini file for the CLI mode needs to be re-edited if the PHP-CLI mode is also enabled for expansion, sudo vim/etc/php/5.6/cli/php.ini , adding a row

Extension=zbarcode.ini

You can then use the PHP-M command to see the Zbarcode module.

Eight, PHP identification of two-dimensional code

Refer to the Php-zbarcode example on GitHub to identify the electronic Business card I just generated.

<?php/* Create New Image Object */$image = new Zbarcodeimage ("./qrcode_vcard.png");/* Create a barcode scanner */$scann  ER = new Zbarcodescanner ();/* Scan the image */$barcode = $scanner->scan ($image);/* Loop through possible barcodes */if (!empty ($barcode)) {foreach ($barcode as $code) {printf ("Found type%s barcode with Data%s\n", $code [' type '], $code [' data ']);}}

Recognition results:

Found type Qr-code barcode with data begin:vcardversion:2.1n:jin;mingcfn:mingcorg:free Mantitle:phpertel; work; Voice:1382173xxxxtel; HOME; Voice:1383284xxxxadr; work; Tianjin, Chinalabel; work; Encoding=quoted-printable:tianjin, China (LABEL; Work) ADR; HOME; Tianjin, Chinalabel; HOME; Encoding=quoted-printable:tianjin, China (LABEL; HOME) EMAIL; Pref;internet:[email Protected]rev:20171201t005548zend:vcard

Nine, reference links
    • Https://gist.github.com/wacko/39ab8c47cbcc0c69ecfb
    • Zbar Wand/magickwand.h not install_imagemagick-7
    • Zbar compilation and installation on Linux systems

PHP generation, identification of QR code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.