使用phpqrcode.php生成二维码并合并到背景图片上
1.找到phpqrcode类库的phpqrcode.php下载放进你的项目,再引入到你的开发代码中
(2)引入:include_once("/library/phpqrcode/phpqrcode.php");
(3)直接贴代码
public function getActivityImg($bg_img, $url, $x=0, $y=0, $qrcode_size, $white_edge=0, $echo_path){
include_once("/library/phpqrcode/phpqrcode.php");
$errorCorrectionLevel = QR_ECLEVEL_L;
$matrixPointSize = 2;
$qrcode = "qrcod.png";
QRcode::png($url, $qrcode, $errorCorrectionLevel, $matrixPointSize, $white_edge);
$background = imagecreatefromstring(file_get_contents($bg_img));
$qrcode_res = imagecreatefromstring(file_get_contents($qrcode));
list($src_w, $src_h) = getimagesize($qrcode);
imagecopyresampled($background, $qrcode_res, $x, $y, 0, 0, $qrcode_size, $qrcode_size, $src_w, $src_h);
if(!is_dir(dirname($echo_path))){
mkdir(dirname($echo_path), 0755, true);
chown(dirname($echo_path), 'nobody');
chgrp(dirname($echo_path), 'nobody');
}
imagepng($background,$echo_path);
imagedestroy($background);
imagedestroy($qrcode_res);
return $echo_path;
}