您的位置:首页 > 编程语言 > PHP开发

使用PHP生成带LOGO的个性化二维码图像

2013-11-22 23:00 591 查看
下面是在二维码QR图中加LOGO的实现方法,其主要步骤有:

1、生成QR原图;

2、以加水印的方式加上LOGO图片。

这样就可以生成个性化的二维码了。

$data
 
'http://www.28ex.net'
;


02.
$size
 
'200x200'
;


03.
$logo
 
'./logo.jpg'
;   
//
中间那logo图


04.
 

05.
//
通过google api生成未加logo前的QR图,也可以自己使用RQcode类生成


06.
$png
 
'http://chart.googleapis.com/chart?chs='
 
$size
 
.
'&cht=qr&chl='
 
.
urlencode(
$data
)
. 
'&chld=L|1&choe=UTF-8'
;


07.
 

08.
$QR
 
=
imagecreatefrompng(
$png
);


09.
if
(
$logo
 
!==
FALSE)


10.
{


11.
$logo
 
=
imagecreatefromstring(
file_get_contents
(
$logo
));


12.
 

13.
$QR_width
 
=
imagesx(
$QR
);


14.
$QR_height
 
=
imagesy(
$QR
);


15.
 

16.
$logo_width
 
=
imagesx(
$logo
);


17.
$logo_height
 
=
imagesy(
$logo
);


18.
 

19.
$logo_qr_width
 
$QR_width
 
/
5;


20.
$scale
 
$logo_width
 
$logo_qr_width
;


21.
$logo_qr_height
 
$logo_height
 
$scale
;


22.
$from_width
 
=
(
$QR_width
 
$logo_qr_width
)
/ 2;


23.
 

24.
imagecopyresampled(
$QR
$logo
$from_width
$from_width
,
0, 0,
$logo_qr_width
$logo_qr_height
$logo_width
$logo_height
);


25.
}


26.
header(
'Content-type:
image/png'
);


27.
imagepng(
$QR
);


28.
imagedestroy(
$QR
);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 二维码 图片