【PHP】PHPqrCode⼆维码类库使⽤⽅法
1.⾸先去官⽹下载PHPqrCode库⽂件,只需要⾥⾯的phpqrcode.php⽂件,下载地址:phpqrcode.sourceforge
2.⼆维码⽣成实例代码:
1 <?php
2/*
3PHPqrCode是⼀个PHP⼆维码⽣成类库,利⽤它可以轻松⽣成⼆维码,官⽹提供了下载和多个演⽰demo,
4
5查看地址:phpqrcode.sourceforge/。
6下载官⽹提供的类库后,只需要使⽤phpqrcode.php就可以⽣成⼆维码了,当然您的PHP环境必须开启⽀持GD2。 phpqrcode.php提供了⼀个关键的png()⽅法,其中参数$text表⽰⽣成⼆位的的信息⽂本;参数$outfile表⽰是否输出⼆维码图⽚⽂ 7
8
9
10调⽤PHP qrCode⾮常简单,如下代码即可⽣成⼀张内容为"www.****"的⼆维码.
11*/
12
13include 'PHPqrCode/phpqrcode.php';  //引⼊phpqrcode类⽂件
14
15$value = 'www.518shen'; //⼆维码内容
16
17$errorCorrectionLevel = 'L';//容错级别
18
19$matrixPointSize = 6;//⽣成图⽚⼤⼩
20
21//⽣成⼆维码图⽚
22
23 QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
24
25$logo = 'logo.png';//准备好的logo图⽚需要加⼊到⼆维码中的logo
26
27$QR = 'qrcode.png';//已经⽣成的原始⼆维码图
28
29
30
31if ($logo !== FALSE) {
32
33$QR = imagecreatefromstring(file_get_contents($QR));
34
35$logo = imagecreatefromstring(file_get_contents($logo));
36
37$QR_width = imagesx($QR);//⼆维码图⽚宽度
38
39$QR_height = imagesy($QR);//⼆维码图⽚⾼度
40
41$logo_width = imagesx($logo);//logo图⽚宽度
42
43$logo_height = imagesy($logo);//logo图⽚⾼度
44
45$logo_qr_width = $QR_width / 5;
46
47$scale = $logo_width/$logo_qr_width;
48
49$logo_qr_height = $logo_height/$scale;
50
51$from_width = ($QR_width - $logo_qr_width) / 2;
php手机版下载
52
53//重新组合图⽚并调整⼤⼩
54
55    imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
56
57$logo_qr_height, $logo_width, $logo_height);
58
59 }
60
61//输出图⽚
62
63 imagepng($QR, 'helloweba.png');
64
65echo '<img src="helloweba.png">';
66
67 ?>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。