PHP generates two-dimensional code in several ways [go]

Source: Internet
Author: User
Tags php class

 

Two-dimensional code is a two-dimensional barcode, can be the URL, text, photos and other information through the corresponding encoding algorithm compiled into a block-shaped barcode pattern, mobile phone users can use the camera and decryption software to re-decode the relevant information and view the content. PHP can generate two-dimensional code using the PHP QR code class library.

The application of QR code can be ordered here (Baidu Encyclopedia).
1.google Open API
$urlToEncode = "http://gz.altmi.com";
Generateqrfromgoogle ($urlToEncode);
function Generateqrfromgoogle ($chl, $widhtHeight = ' Max ', $EC _level= ' L ', $margin = ' 0 ')
{
$url = UrlEncode ($url);
Echo ' ';
}
2.php class library PHP QR Code
PHP QR Code is the Open source (LGPL) library for generating QR code,
2-dimensional Barcode. Based on Libqrencode C Library,
Provides API for creating QR Code barcode Images (PNG, JPEG thanks to GD2).
Implemented purely in PHP, with no external dependencies (except GD2 if needed).

Use cases:
<?php
Include ('./phpqrcode/phpqrcode.php ');
Two-dimensional code data
$data = ' http://gz.altmi.com ';
The generated file name
$filename = $errorCorrectionLevel. ' | '. $matrixPointSize. " PNG ';
Error correction level: L, M, Q, H
$errorCorrectionLevel = ' L ';
Size of point: 1 to 10
$matrixPointSize = 4;
QRCode::p ng ($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
The official given use case:
<?php
# include one of these two files:
/*
qrlib.php for full version (also the Provide all library files
Form package plus cache dir)

OR phpqrcode.php for merged version (only one file,
But slower and less accurate code because disabled cache
and quicker masking configured)
*/
# Two words to explain:
# contains qrlib.php words need to be put together with other files: files, folders.
# phpqrcode.php is a merged version that only needs to contain this file, but the resulting picture is slow and less accurate
# Here are two ways to use:

# Create a two-dimensional code file
QRCode::p ng (' Code data text ', ' filename.png ');
Creates file

# Generate image to browser
QRCode::p ng (' some othertext 1234 ');
Creates code image and outputs it directly into browser

Address: http://phpqrcode.sourceforge.net/
Download: http://sourceforge.net/projects/phpqrcode/

3.libqrencode

Address: http://fukuchi.org/works/qrencode/index.en.html
PHP support please refer to: http://hirokawa.netflowers.jp/entry/4900/

4.QRcode Perl CGI & PHP Scripts
Address: http://www.swetake.com/qr/qr_cgi.html

Original: http://blog.chinaunix.net/uid-20787846-id-3492930.html

---------------

Using the PHP QR code class library to create a QR code

Using an example browser output:

<?
Include "phpqrcode/phpqrcode.php";
$value = "Http://s.bookphone.cn/chinabook/index.php/adminhtml/Croles/admin";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRCode::p ng ($value, False, $errorCorrectionLevel, $matrixPointSize);
Exit
?>

File output two-dimensional code

Include (' phpqrcode/phpqrcode.php ');
Two-dimensional code data
$data = ' http://s.bookphone.cn ';
The generated file name
$filename = ' 1111.png ';
Error correction level: L, M, Q, H
$errorCorrectionLevel = ' L ';
Size of point: 1 to 10
$matrixPointSize = 4;
QRCode::p ng ($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);

Create a two-dimensional code with logo in the middle

<?php
Include (' phpqrcode/phpqrcode.php ');
$value = ' http://xy.bookphone.cn ';
$errorCorrectionLevel = ' L ';
$matrixPointSize = 6;
QRCode::p ng ($value, ' xiangyang.png ', $errorCorrectionLevel, $matrixPointSize, 2);
echo "QR code generated". " <br/> ";
$logo = ' logo.png ';
$QR = ' xiangyang.png ';

if ($logo!== FALSE)
{

$QR = imagecreatefromstring (file_get_contents ($QR));
$logo = imagecreatefromstring (file_get_contents ($logo));
$QR _width = Imagesx ($QR);
$QR _height = Imagesy ($QR);
$logo _width = Imagesx ($logo);
$logo _height = Imagesy ($logo);
$logo _qr_width = $QR _width/5;
$scale = $logo _width/$logo _qr_width;
$logo _qr_height = $logo _height/$scale;
$from _width = ($QR _width-$logo _qr_width)/2;
Imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_height, $logo _width, $logo _ height);
}
Imagepng ($QR, ' xiangyanglog.png ');
?>

PHP generates two-dimensional code in several ways [go]

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.