[php]-[01]-Generate and save QR code

Source: Internet
Author: User

Resource files that need to be used:

Http://files.cnblogs.com/files/Eyes-Chan/phpqrcode-2010100721_1.1.4.zip

In fact, you only need to use the phpqrcode.php in the resource file above. (If you're using a CI framework, just put the phpqrcode.php file in the controller layer)

How to use:

<?php

$str = ' http://www.google.com '; Public function make_qrcode ($str) { include ' phpqrcode.php '; QRCode::p ng ($str); }

?>

If you want to create a QR code and save it directly:

<?PHP//generates a two-dimensional code for a string that is referred to by the $STR and is stored in the path of the $FILENAME's referring generation$str= ' http://www.google.com ';$filename= '/*the URL want to save the QRCode image*/'; Public functionMake_save_qrcode ($str,$filename){    include' Phpqrcode.php '; QRCode::p ng ($str,$filename,$pixelPerPoint= 4,$outerFrame= 4,$saveandprint=false);}?>

If you want to create a QR code with logo and save it directly:

<?PHP$value= ' www.google.com ';//Two-dimensional code content$filename= '/*the URL want to save your QRCode image*/'; Public functionMake_qrcode ($value){    include' Phpqrcode.php '; $errorCorrectionLevel= ' L ';//Fault tolerance level    $matrixPointSize= 6;//Generate picture size//Generate two-dimensional code pictureQRCode::p ng ($value, ' Qrcode.png ',$errorCorrectionLevel,$matrixPointSize, 2); $logo= ' logo.png ';//Ready logo Image    $QR= ' qrcode.png ';//original two-dimensional code diagram that has been generated            if($logo!==FALSE) {         $QR= Imagecreatefromstring (file_get_contents($QR)); $logo= Imagecreatefromstring (file_get_contents($logo)); $QR _width= Imagesx ($QR);//Two-dimensional code image width        $QR _height= Imagesy ($QR);//Two-dimensional code image height        $logo _width= Imagesx ($logo);//logo image Width        $logo _height= Imagesy ($logo);//logo Image Height        $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; //Regroup and resize picturesImagecopyresampled ($QR,$logo,$from _width,$from _width, 0, 0,$logo _qr_width,$logo _qr_height,$logo _width,$logo _height); }         //Save PictureImagepng ($QR,$filename); }?>

These are the three commonly used methods, so if you need the details of the adjustment, or to meet other requirements, you can study the phpqrcode.php this class library file.

[php]-[01]-Generate and save QR code

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.