Home > php教程 > php手册 > body text

Generate QR code with picture

WBOY
Release: 2016-09-07 12:57:58
Original
1633 people have browsed it

I just started trying it myself, and it may not be easy for the masters to understand. I hope it will be useful.

Steps: 1. Download the phpqrcode.php file from the website http://phpqrcode.sourceforge.net/, and then put it into your own project;

        2. Write code and introduce phpqrcode.php file to generate QR code.

Code:

1. phpqrcode.php file (just download it)

2. Test code (erweima.app.php)

? & Lt;? PHP

/*
*generates a two-dimensional code
*/
Class EXTENDS ShoppingBaseApp {

Function INDEX () {
$ this- & gt; display ('ERWEIMA. html ');}

/**
* @param string $chl The information contained in the QR code can be numbers, characters, binary information, or Chinese characters.型 cannot be mixed with data types. The data must be set through UTF-8 URL-ENCODED
* @Param int $ widhtheighhead. Settings of the QR code to generate QR codes
@Param String $ EC_LEVEL can be selected. QR code supports four levels of error correction. , used to recover lost, misread, ambiguous, data.
          * L-Default: Can identify 7% of the data that has been lost
       * M- Can identify the data that has been lost by 15%
       * Q- Can identify the data that has been lost by 25%
        * H- Can identify the data that has been lost by 30% Data
  * @param int $margin The distance between the generated QR code and the picture border
 */
function credit_qrcode()
{
include '/includes/libraries/phpqrcode.php';
$value = isset($_POST['url']) ? $_POST['url'] : 'http://www.baidu.com';
                                                                                                 $image = $this->_upload_file('image', 'erweima/', date('YmdHis') . mt_rand(1000, 9999), 'index.php?app=credit&act=credit_qrcode');
     if ($image){
                                                                                 styles/default/images/001.jpg';//Ready logo image
      }
            $errorCorrectionLevel = 'H'; // Error tolerance level
                    $matrixPointSize = 8;     // Generate image size
        //   Generate QR code image
  QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
$QR = 'qrcode.png';//The original QR code image that has been generated
     
      if($logo !== FALSE){
              $QR = imagecreatefromstring(file_get_contents($ QR));
            $logo = imagecreatefromstring(file_get_contents($logo));
                                                                      using QR using using QR code using  -                                                          Height
                $logo_width = imagesx($logo);                        $scale = $logo_width/$logo_qr_width;
                                                                      resampled($QR, $logo, $from_width, $from_width, 0, ' }

/**
        * Upload file
     * @return mix false means upload failed, empty string means no upload, string means upload file address
       * $file_name is the name of the uploaded file
      * $path_name is the upload path
      * $save_name is the name of the saved file
       * $ret_url is the callback URL
**/
function _upload_file($file_name, $path_name, $save_name, $ret_url = 'index.php')
{
$file = $_FILES[$file_name];
$message = array(
'1' => 'The uploaded file exceeds the limit of the upload_max_filesize option in php.ini. ',
' '2' => 'The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form. ',
'3' => 'Only part of the file was uploaded. '
' ' );
' ' switch ($file['error'])
' ' E:
             case UPLOAD_ERR_PARTIAL:
                                                                                                                                               
                  $this->show_warning($message[$file['error']], 'go_back');                                                             {
                        return array('done' => FALSE, 'msg' => $message[$file['error']]);
                                                                                                                                                 Return '';
}
import(' uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
if ($uploader->file_info() = == false)
                                                                                                                                              return false; return array('done' => FALSE, 'msg' => $uploader->get_error()); ;save ('data/files/mall/'.$path_name, $save_name);
}
}



3. Template file (erweima.html)

 


       

               请输入网址:

               图片上传:

              
       

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template