PHP identification QR Code (reproduced)

Source: Internet
Author: User

Near paragraph need to write a PHP to identify the QR code function, on-line search for a long time to solve the problem. To record the way to solve the problem.

The first way to find is a called php-zbarcode extension, the installation of their own according to the network installed ImageMagick and zbar , but the compile php-zbarcode error, and later replaced by the center OS system or error, due to the limited technology will give up.

Then we found a extension on GitHub called Php-qrcode-detector-decoder, and the installation method and usage are as follows, but only two-dimensional images can be identified after the installation is complete. But the QR code in a picture is not recognized (only a small part of the graph is a QR code). Did not meet my needs and continue to look for some.

//在控台执行安装composer require khanamiryan/qrcode-detector-decoder//使用方法require __DIR__ . "/vendor/autoload.php";  $qrcode = new QrReader('path/to_image');$text = $qrcode->text();         //返回二维码的内容

Finally, I found out that Php-qrcode-detector-decoder is based on? Zxing Library (Google launched to identify a variety of format bar code Open source project), and I also successfully found the Zxing library GitHub address, which includes a lot of language QR code recognition, interested can see for themselves. Below we use the php-zxing extension.

Introduce the extension in the composer file and then composer update{"require": {"dsiddharth2/php-zxing": "Dev-master"}}//code use in PHP  Phpzxing\phpzxingdecoder; $config = Array (' try_harder ' = = true,//When you do not know the location of the QR code is set to True ' multiple_bar_codes ' = True,//when to identify multiple QR codes is set to true ' crop ' = ' 100,200,300,300 ',//Set approximate location of QR code; $decoder = new Phpzxingdecoder ($confi  g); $decoder->setjavapath ('/your/path/to/java '); Set the installation path for the JDK, which is in Java and requires a JDK. If you set the environment variable for the JDK, you do not need to set $decodeddata = current ($decoder->decode ('. /images/code128barcode.jpg '));            The path requires an absolute path or relative path, cannot be a url/** * returned object type * The Zxingimage object that is returned when the recognition succeeds includes the contents of the * getimagevalue QR code * GetFormat Format of encoded image * GetType gets the type of decoded image, for example: Url,text etc * Getimagepath get image Path * not recognized in picture QR Code returns zxingbarnotfound object includes * Getimageerrorcode error code to get the image not found * geterrormessage error message * Geti  Magepath gets the path of the image/**//such as $decodeddata->getimagevalue (); Two-dimensional code content

This article transferred from: https://www.jianshu.com/p/91eb7452548a
If you want to reprint, please specify the source: http://www.cnblogs.com/zhuchenglin/p/8352755.html

PHP identification QR Code (reproduced)

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.