关于php生成二维码

//  方法一:使用PHP QR Code类库创建二维码

<?php
        include "phpqrcode/phpqrcode.php";
	
	$value="http://www.baidu.com"; // 生成的源代码
	$errorCorrectionLevel = "L"; // 错误率
	$matrixPointSize = "20";  // 大小
	
	if (isset($_GET['logo'])) {	
		$logo = 'firefox.png'; // 二维码中间的logo
		$QR = 'baidu_map.png'; // 目标生成的二维码
		
		QRcode::png($value, 'baidu_map.png', $errorCorrectionLevel, $matrixPointSize, 2);

		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_height = imagesy($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);
		}
		
		imagepng($QR,'baidu_map.png');
		
	}else {
	
		$file_name = "baidu.jpg";  // 是否生成图片, false 输出到浏览器
		
		QRcode::png($value, $file_name, $errorCorrectionLevel, $matrixPointSize);
		
	}

?>


//  方法二:Google提供了较为完善的二维码生成接口,调用API接口(本人测试未成功)

<?php

	header("Content-Type:text/html;charset=utf-8");
	
	if (isset($_GET['content'])) {
		$content = $_GET['content'];
		$width = $_GET['width']?$_GET['width']:300;
		$height = $_GET['height']?$_GET['height']:300;
		
		echo "你输入的内容是: <span>$content </span><BR />";
		echo "你选择的宽度是: <span>$width </span><BR />";
		echo "你选择的高度是: <span>$height </span><BR /> ";
		echo "生成的二维码图像是:<BR /> ";
		$wen = urlencode(mb_convert_encoding($content, 'utf-8', 'gb2312'))."";
		echo "<img id=qrcode_img src=https://chart.googleapis.com/chart?cht=qr&chld=H&chs={$width}x{$height}&chl={$wen} /><br />
		图片地址:<a href='https://chart.googleapis.com/chart?cht=qr&chld=H&chs={$width}x{$height}&chl={$wen}' target='_blank'>点击跳转</a> ";
	}
?>
<form action="" method="get" οnsubmit="return post();">
	<h1>二维码生成工具</h1>
	<p>
		width:
			<select name="width">
				<option value="100">100</option>
				<option value="200">200</option>
				<option value="300" Selected>300</option>
				<option value="400">400</option>
				<option value="500">500</option>
			</select>
		height: 
			<select name="height">
				<option value="100">100</option>
				<option value="200">200</option>
				<option value="300" Selected>300</option>
				<option value="400">400</option>
				<option value="500">500</option>
			</select>
	</p>
	输入网址或者文字:<br />
	<textarea rows="5" cols="30" name="content" id="content" ></textarea><br /><br />
	<input type="submit" value="生成图片" />
</form>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值