commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
define('IN_ECS', true); |
|
3 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
4 |
require(dirname(__FILE__) . '/includes/phpqrcode.php'); |
|
5 |
|
|
6 |
|
|
7 |
if(isset($_REQUEST['data']) && !empty($_REQUEST['data'])){ |
|
8 |
$data= $_REQUEST['data']; |
|
9 |
//$size = '250x250'; |
|
10 |
$img = $_REQUEST['img']; |
|
11 |
$logo = str_replace("..", ".", $img); // 中间那logo图 |
|
12 |
}else{ |
|
13 |
$id= isset($_GET['id']) ? intval($_GET['id']) : 0; |
|
14 |
$data = str_replace('{id}', $id, $_CFG['erweima_wapurl']); |
|
15 |
|
|
16 |
//$size = '250x250'; |
|
17 |
$logo = str_replace("..", ".", $_CFG['erweima_logo']); // 中间那logo图 |
|
18 |
} |
|
19 |
|
|
20 |
$errorCorrectionLevel = 'L';//容错级别 |
|
21 |
$matrixPointSize = 6;//生成图片大小 |
|
22 |
//生成二维码图片 |
|
23 |
QRcode::png($data, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2); |
|
24 |
|
|
25 |
$QR = 'qrcode.png';//已经生成的原始二维码图 |
|
26 |
|
|
27 |
if ($logo !== FALSE) { |
|
28 |
$QR = imagecreatefromstring(file_get_contents($QR)); |
|
29 |
$logo = imagecreatefromstring(file_get_contents($logo)); |
|
30 |
$QR_width = imagesx($QR);//二维码图片宽度 |
|
31 |
$QR_height = imagesy($QR);//二维码图片高度 |
|
32 |
$logo_width = imagesx($logo);//logo图片宽度 |
|
33 |
$logo_height = imagesy($logo);//logo图片高度 |
|
34 |
$logo_qr_width = $QR_width / 5; |
|
35 |
$scale = $logo_width/$logo_qr_width; |
|
36 |
$logo_qr_height = $logo_height/$scale; |
|
37 |
$from_width = ($QR_width - $logo_qr_width) / 2; |
|
38 |
//重新组合图片并调整大小 |
|
39 |
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, |
|
40 |
$logo_qr_height, $logo_width, $logo_height); |
|
41 |
} |
|
42 |
//输出图片 |
|
43 |
//imagepng($QR, 'helloweba.png'); |
|
44 |
//echo '<img src="helloweba.png">'; |
|
45 |
header('Content-type: image/png'); |
|
46 |
imagepng($QR); |
|
47 |
imagedestroy($QR); |
|
48 |
|
|
49 |
exit; |
|
50 |
|
|
51 |
// 通过google api生成未加logo前的QR图,也可以自己使用RQcode类生成 |
|
52 |
|
|
53 |
$png = 'http://chart.googleapis.com/chart?chs=' . $size . '&cht=qr&chl=' . urlencode($data) . '&chld=L|1&choe=UTF-8'; |
|
54 |
|
|
55 |
$QR = imagecreatefrompng($png); |
|
56 |
if($logo !== FALSE) |
|
57 |
{ |
|
58 |
$logo = imagecreatefromstring(file_get_contents($logo)); |
|
59 |
|
|
60 |
$QR_width = imagesx($QR); |
|
61 |
$QR_height = imagesy($QR); |
|
62 |
|
|
63 |
$logo_width = imagesx($logo); |
|
64 |
$logo_height = imagesy($logo); |
|
65 |
|
|
66 |
$logo_qr_width = $QR_width / 5; |
|
67 |
$scale = $logo_width / $logo_qr_width; |
|
68 |
$logo_qr_height = $logo_height / $scale; |
|
69 |
$from_width = ($QR_width - $logo_qr_width) / 2; |
|
70 |
|
|
71 |
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); |
|
72 |
} |
|
73 |
header('Content-type: image/png'); |
|
74 |
imagepng($QR); |
|
75 |
imagedestroy($QR); |
|
76 |
?> |