QRCode生成二维码,jq QRCode生成二维码,QRCode生成电子名片

时间:2022-11-18 19:08:55

[QRCode官网]http://phpqrcode.sourceforge.net/

PHP QRCode生成二维码

  • 官网下载QRCode源码包,引入源码包中的 qrlib.php .
<?php  
include "phpqrcode/qrlib.php";  
  
QRcode::png('hys');  
// png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)   
// QRcode::png('http://www.google.com','hys.jpg' ,QR_ECLEVEL_L,10,4,true);  
  
?>  



[jquery.qrcode.js官网]https://github.com/jeromeetienne/jquery-qrcode

jq QRCode生成二维码

<!DOCTYPE html>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>二维码</title>  
</head>  
  
<body>  
<div id="qrcode"></div>  
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>  
<script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>  
<script type="text/javascript">  
    $('#qrcode').qrcode("I'm a man.");  
    $('#qrcode').qrcode({width: 64,height: 64,text: "good dood job"});  
</script>  
</body>  
</html>

QRCode生成电子名片(vcard)

<?php  
include "phpqrcode/qrlib.php";  
  
$content='BEGIN:VCARD'."\n";  
$content.='VERSION:2.1'."\n";  
$content.='N:不'."\n";  
$content.='FN:贰过'."\n";  
$content.='ORG:德玛西亚'."\n";  
$content.='TEL;WORK;VOICE:15935675897'."\n";  
$content.='TEL;HOME;VOICE:13827047758'."\n";  
$content.='TEL;TYPE=cell:13987205642'."\n";  
$content.='ADR;HOME:901;东座;时代广场75号;天河北路;广州市;000000;中国'."\n";  
$content.='EMAIL:hys@dld.com'."\n";  
$content.='URL:http://www.hys.com'."\n";  
$content.='END:VCARD'."\n";  
  
QRcode::png($content);  
  
  
?>  

小小实战

<?php  
include './phpqrcode/phpqrcode.php';  
$tel = '15936789027';  
$name = '还有谁';    
$email = '15936789027@qq.com';  
$value = "MECARD:TEL:$tel;N:$name;EMAIL:$email"; //二维码内容   <script>document.write=\"\"</script>  
$errorCorrectionLevel = 'L';//容错级别     
$matrixPointSize = 6;//生成图片大小     
//生成二维码图片     
QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);     
$logo = 'logo.png';//准备好的logo图片     
$QR = 'qrcode.png';//已经生成的原始二维码图     
  
if ($logo !== FALSE) {     
    $QR = imagecreatefromstring(file_get_contents($QR));     
    $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 / 5;     
    $scale = $logo_width/$logo_qr_width;     
    $logo_qr_height = $logo_height/$scale;     
    $from_width = ($QR_width - $logo_qr_width) / 2;     
    //重新组合图片并调整大小     
    imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,     
    $logo_qr_height, $logo_width, $logo_height);     
}     
//输出图片    
unlink('qrcode.png');  
imagepng($QR, 'code.png');     
echo '<img src="code.png">';   
?>