PHP生成动态二维码_phpqrcode二维码生成实例教程

 更新 2020-09-26 浏览 873次

PHP生成动态二维码_phpqrcode二维码生成实例教程
描述:该实例主要是通过PHP二维码生成类phpqrcode插件来实现的在线二维码动态生成,可自定义二维码大小、容错级别、跳转地址、logo设置等等功能,功能非常强大实用。
基础属性
详细介绍

一、引入phpqrcode.php类文件

include_once 'phpqrcode.php';

二、调用方法生成二维码

//二维码内容
$value = 'http://www.mabangzhu.com'; 
//容错级别
$errorCorrectionLevel = 'L';
//生成图片大小
$matrixPointSize = 6;
//生成二维码图片
QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
//准备好的logo图片
$logo = 'logo.png';
//已经生成的原始二维码图
$QR = 'qrcode.png';
//给二维码添加LOGO
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图片宽度
$logo_height = imagesy($logo);//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, 'helloweba.png');

三、输出二维码图片

<img src="helloweba.png" alt="码帮主_二维码"/>


二维码生成插件PHP生成二维码二维码生成实例phpqrcode
相关内容