PHP calls Google interface to generate QR code sample codes

Source: Internet
Author: User
Tags urlencode
Google provides a generation of two-dimensional code interface, through the interface we can generate two-dimensional code, convenient and fast.

Interface address http://chart.apis.google.com/chart?chs= width high value x Width high value &cht=qr&chld= level | margin &chl= content

Parameter description:

Wide-high value: Generate two-dimensional code size, units are pixels, the current generated QR codes are square, so the two width and height values are set to the same value

Rating: Four levels, L Default: can identify lost 7% of the data, M can identify the loss of 15% of the data, Q can identify the loss of 25% of the data, H-can identify the loss of 30% of data

Margin: The distance from the picture border generated by the QR code

Content: Generate two-dimensional code content, but must be urlencode

<?php $data = isset ($_get[' t '])? $_get[' t ']: ' http://www.XXX.com '; $size = isset ($_get[' size ')? $_get[' size ': ' 150x150 '; $logo = isset ($_get[' logo ')? $_get[' logo ']: "./image/logo.jpg"; $chl = UrlEncode ($logo); $png = "http://chart.googleapis.com/chart?chs= $size &cht=qr&chl= $chl &chld=l|1&choe=utf-8"; $QR = Imagecreatefrompng ($png);//Outside that QR chart if ($logo!== FALSE) {$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); } header (' Content-type:image/png '); Imagepng ($QR); Imagedestroy ($QR);; 
Related Article

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.