Home > Backend Development > PHP Tutorial > PHP 使用QR code库生成带LOGO图像的二维码

PHP 使用QR code库生成带LOGO图像的二维码

WBOY
Release: 2016-06-20 12:53:47
Original
1111 people have browsed it

这几天的项目中要用到生成二维码的功能,而且老板要求二维码中间有一个LOGO,以往都是生成那种标准的,也就是比较纯净的二维码,现在老板的这个要求,一时让我无头绪,不过经过努力查找资料,发现PHP中有一个类库叫php qrcode,用它来生成这种二维码很是方便,于是就研究下,终于搞定了,下面把代码分享给大家。先来看看生成的效果:

具体的PHP代码,先调用phpqrcode.php,然后看代码里的注释,然后把 www.codesc.net这个网址修改成你自己的,还有logo图片替换成你的,再修改其它的参数即可:

<?phpinclude ('phpqrcode.php');$value = 'http://www.codesc.net';//二维码数据$errorCorrectionLevel = 'L';//纠错级别:L、M、Q、H$matrixPointSize = 10;//二维码点的大小:1到10QRcode::png ( $value, 'ewm.png', $errorCorrectionLevel, $matrixPointSize, 2 );//不带Logo二维码的文件名echo "二维码已生成" . "<br />";$logo = 'emwlogo.gif';//需要显示在二维码中的Logo图像$QR = 'ewm.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, 'ewmlogo.png' );//带Logo二维码的文件名?>
Copy after login

phpqrcode.php类库可以在这里下载:http://sourceforge.net/projects/phpqrcode/

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template