Thinkphp 调用Qrcode生成二维码

$save_file = MY_ROOT_PATH."/uploads/qrcode_wxa/";//项目存储二维码的目录地址,自定义
if (!is_dir($save_file)){
	mkdir($save_file);
}
$save_file .= 'shanghu_'.$suppliersn.".png";//自定义二维码名称,最好不重复
if (!file_exists($save_file)){
    
  $value = 'http://www.baidu.com?sellerid='.$suppliersn;//扫描跳转的地址,参数自己拼接
  $header_img = $head_logo_file;//二维码中间的头像,可忽略
  $this->_abot_qrcode_with_header($value, $save_file, $header_img);	


}

$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';

//取二维码通过http打头的图片地址(刚刚自己定义的存储位置)
$qrcode_url = $sys_protocal.$this->get_current_domain().__ROOT__."/uploads/qrcode_wxa/".'shanghu_'.$suppliersn.".png";



//封装了生成二维码的方法

protected  function _abot_qrcode_with_header($value, $qrcode_img, $header_img){
		require_once APP_PATH.'Extend/Vendor/phpqrcode/phpqrcode.php';//生成二维码的类
		
		$errorCorrectionLevel = 'H';//容错级别
		$matrixPointSize = 10;//生成图片大小
		//生成二维码图片
		$ret = QRcode::png($value, $qrcode_img, $errorCorrectionLevel, $matrixPointSize, 2);
		
		$logo = $header_img;//准备好的logo图片
		$QR = $qrcode_img;//已经生成的原始二维码图
		
		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);
		}
		//输出图片
		imagepng($QR, $qrcode_img);
		//echo '<img src="'.$qrcode_img.'">';
	}

 

转载于:https://my.oschina.net/u/3408149/blog/1580834

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值