1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| require_once "tools/phpqrcode/phpqrcode.php";
class Phpqrcode_Model extends CI_Model {
function __construct()
{
parent::__construct();
}
public $upload_dir = "/var/www/html/downloads/";
public function phpqrcode($data, $logo = "")
{
$data = "http://abc.xyz/iadsfnasfjasudsdfdmsfjajfwsfasfsafsafsdfsfsfasafsdfsdfsfsfsfsf";
$logo = "/var/www/html/rs/images/login/logo192.png";
$dt = date('Ymd_His_');
$username = isset($_SESSION['username']) ? $_SESSION['username'] : '';
$path = $this->upload_dir . $dt . $username . "/";
if (!is_dir($path))
mkdir($path);
$fullpath = $path . $dt . 'qrcode.png';
$object = new \QRcode();
$errorCorrectionLevel = 'Q'; // 容错级别 L 7%, M 15%, Q 25%, H 30%
$matrixPointSize = 10; // 生成图片大小(这个值可以通过参数传进来判断)
$margin = 2; // 二维码图片的margin值,就是二维码图边距值
$object->png($data, $fullpath, $errorCorrectionLevel, $matrixPointSize, $margin);
// 判断是否生成带logo的二维码
if (file_exists($logo))
{
$QR = imagecreatefromstring(file_get_contents($fullpath)); // 目标图象连接资源。
$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 / 4; // 组合之后logo的宽度(占二维码的1/5)
$scale = $logo_width / $logo_qr_width; // logo的宽度缩放比(本身宽度/组合后的宽度)
$logo_qr_height = $logo_height / $scale; // 组合之后logo的高度
$from_width = ($QR_width - $logo_qr_width) / 2; // 组合之后logo左上角所在坐标点
// 重新组合图片并调整大小
// imagecopyresampled() 将一幅图像(源图象)中的一块正方形区域拷贝到另一个图像中
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
// 输出图片
imagepng($QR, $fullpath);
imagedestroy($QR);
imagedestroy($logo);
}
$QR = imagecreatefromstring(file_get_contents($fullpath)); // 目标图象连接资源。
header('Content-Type: image/png');
imagepng($QR);
die();
$filename = $fullpath;
$pos = strpos($filename, "/" . FSNAME . "/downloads/");
$fullname = substr($filename, $pos);
$tmp = explode('/', $filename);
$filename = $tmp[count($tmp)-1];
var_dump($filename);
var_dump($fullname);
echo "<br>";
echo "<a target=_blank href='{$fullname}'>{$filename}</a><br>";
die();
$result['errcode'] = 0;
$result['errmsg'] = 'ok';
$result['data'] = $fullpath;
return $result;
}
}
|