Generate QR codes and images with images

Source: Internet
Author: User

Generate QR codes and images with images

I just started to try it. It may be difficult for the great gods to get into the eye and hope it will be useful.

Step 1. Download The phpqrcode.php file at http://phpqrcode.sourceforge.net/and then release it to your project;

2. Compile the code and introduce the phpqrcode. php file to generate a QR code.

Code:

1. phpqrcode. php file (download it)

Ii. Test code (erweima. app. php)

<? Php
/*
* Generate a QR code
*/
Class ErweimaApp extends ShoppingbaseApp {

Function index ()
{
$ This-> display('erweima.html ');
}

/**
* @ Param string $ information contained in the chlorophyll QR code, which can be numbers, characters, binary information, and Chinese characters.
Cannot mix data types, data must go through UTF-8 URL-encoded
* @ Param int $ widhtHeight: set the size of the generated QR code
* @ Param string $ EC_level: the error correction level is optional. The QR code supports four levels of error correction, which is used to restore lost, read, fuzzy, and data.
* L-Default: 7% of lost data can be identified.
* M-identifies 15% of data loss
* Q-identifies 25% of data loss
* H-identifies 30% of data loss
* @ Param int $ the distance between the QR code generated by margin and the image border
*/
Function credit_qrcode ()
{
Include '/utilities des/libraries/phpqrcode. php ';
$ Value = isset ($ _ POST ['url'])? $ _ POST ['url']: 'http: // www.baidu.com ';
// Upload an image
If (isset ($ _ FILES ['image']) & $ _ FILES ['image'] ['error'] = 0 ){
$ Image = $ this-> _ upload_file ('image', 'erweima/', date ('ymdhis'). mt_rand (1000,999 9), 'index. php? App = credit & amp; act = credit_qrcode ');
If ($ image ){
$ Logo = $ image;
}
}
Else
{
$ Logo = SITE_URL. '/themes/mall/default/styles/default/images/001.jpg'; // prepared logo image
}
$ ErrorCorrectionLevel = 'H'; // fault tolerance level
$ MatrixPointSize = 8; // generate the image size
// Generate a QR code Image
QRcode: png ($ value, 'qrcode.png ', $ errorCorrectionLevel, $ matrixPointSize, 2 );
$ QR = 'qrcode.png '; // generated original QR code

If ($ logo! = FALSE ){
$ QR = imagecreatefromstring (file_get_contents ($ QR ));
$ Logo = imagecreatefromstring (file_get_contents ($ logo ));
$ QR_width = imagesx ($ QR); // The image width of the QR code.
$ QR_height = imagesy ($ QR); // The Image Height of the QR code.
$ 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;
// Re-combine and resize the image
Imagecopyresampled ($ QR, $ logo, $ from_width, $ from_width, 0, 0, $ logo_qr_width,
$ Logo_qr_height, $ logo_width, $ logo_height );
}
// Output image
Imagepng ($ QR, 'helloweba.png ');
Echo ' ';
}

/**
* Upload a file
* @ Return mix false indicates that the upload fails. A blank string indicates that the upload is not performed, and a string indicates the address of the uploaded file.
* $ File_name indicates the name of the uploaded file.
* $ Path_name indicates the upload path.
* $ Save_name is the file name to save
* $ 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 is uploaded. '
);
Switch ($ file ['error'])
{
Case UPLOAD_ERR_INI_SIZE:
Case UPLOAD_ERR_FORM_SIZE:
Case UPLOAD_ERR_PARTIAL:
If ($ ret_url)
{
$ This-> show_warning ($ message [$ file ['error'], 'Go _ back ');
Return false;
}
Else
{
Return array ('done' => FALSE, 'msg '=> $ message [$ file ['error']);
}
Break;
}
If ($ file ['error']! = UPLOAD_ERR_ OK)
{
Return '';
}
Import ('uploader. lib ');
$ Uploader = new Uploader ();
$ Uploader-> allowed_type (IMAGE_FILE_TYPE );
$ Uploader-> addFile ($ file );
If ($ uploader-> file_info () = false)
{
If ($ ret_url)
{
$ This-> show_warning ($ uploader-> get_error (), 'Go _ back', $ ret_url );
Return false;
}
Else
{
Return array ('done' => FALSE, 'msg '=> $ uploader-> get_error ());
}
}
$ Uploader-> root_dir (ROOT_PATH );
Return $ uploader-> save ('data/files/mall/'. $ path_name, $ save_name );
}
}

Three-digit template file (erweima.html)

<Div style = "height: 100px; border: 1px solid gray; text-align: center; padding-top: 20px;">
<Form action = "index. php? App = erweima & act = credit_qrcode "method =" post "enctype =" multipart/form-data ">
Enter the url: <input type = "text" name = "url"> <br/>
Image Upload: <input type = "file" name = "image"> <br/>
<Input type = "submit" name = "sbt" value = "submit">
</Form>
</Div>

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.