php 二维码生成类
<?php
/**
* BarcodeQR - Code QR Barcode Image Generator (PNG)
* @package BarcodeQR
* @category BarcodeQR
* @name BarcodeQR
* @version 1.0
* @author Shay Anderson 05.11
* @link http://www.shayanderson.com/php/php-qr-code-generator-class.htm
* @license http://www.gnu.org/licenses/gpl.html GPL License
* This is free software and is distributed WITHOUT ANY WARRANTY
*/
final class BarcodeQR {
/**
* Google Chart API URL
*/
const API_CHART_URL = "http://chart.apis.google.com/chart"; /**
* Code data
* @var string $_data
*/
private $_data; /**
* Bookmark code
* @param string $title
* @param string $url
*/
public function bookmark($title = null, $url = null) {
$this->_data = "MEBKM:TITLE:{$title};URL:{$url};;";
} /**
* MECARD code
* @param string $name
* @param string $address
* @param string $phone
* @param string $email
*/
public function contact($name = null, $address = null, $phone = null, $email = null) {
$this->_data = "MECARD:N:{$name};ADR:{$address};TEL:{$phone};EMAIL:{$email};;";
} /**
* Create code with GIF, JPG, etc.
* @param string $type
* @param string $size
* @param string $content
*/
public function content($type = null, $size = null, $content = null) {
$this->_data = "CNTS:TYPE:{$type};LNG:{$size};BODY:{$content};;";
} /**
* Generate QR code image
* @param int $size
* @param string $filename
* @return bool
*/
public function draw($size = 150, $filename = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::API_CHART_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$size}x{$size}&cht=qr&chl=" . urlencode($this->_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$img = curl_exec($ch);
curl_close($ch); if ($img) {
if ($filename) {
if (!preg_match("#\.png$#i", $filename)) {
$filename .= ".png";
} return file_put_contents($filename, $img);
} else {
header("Content-type: image/png");
print $img;
return true;
}
} return false;
} /**
* Email address code
* @param string $email
* @param string $subject
* @param string $message
*/
public function email($email = null, $subject = null, $message = null) {
$this->_data = "MATMSG:TO:{$email};SUB:{$subject};BODY:{$message};;";
} /**
* Geo location code
* @param string $lat
* @param string $lon
* @param string $height
*/
public function geo($lat = null, $lon = null, $height = null) {
$this->_data = "GEO:{$lat},{$lon},{$height}";
} /**
* Telephone number code
* @param string $phone
*/
public function phone($phone = null) {
$this->_data = "TEL:{$phone}";
} /**
* SMS code
* @param string $phone
* @param string $text
*/
public function sms($phone = null, $text = null) {
$this->_data = "SMSTO:{$phone}:{$text}";
} /**
* Text code
* @param string $text
*/
public function text($text = null) {
$this->_data = $text;
} /**
* URL code
* @param string $url
*/
public function url($url = null) {
$this->_data = preg_match("#^https?\:\/\/#", $url) ? $url : "http://{$url}";
} /**
* Wifi code
* @param string $type
* @param string $ssid
* @param string $password
*/
public function wifi($type = null, $ssid = null, $password = null) {
$this->_data = "WIFI:T:{$type};S{$ssid};{$password};;";
}
} // 生成二维码 Demo
$qrimage_path = '/home/www';
$qr = new BarcodeQR();
$qr_text = '[User ID] Content';
$uri_hash = md5($user_id);
$qrimg_file = $qrimage_path . DIRECTORY_SEPARATOR . $uri_hash . '.png'; $qr->text($qr_text); return $qr->draw(154, $qrimg_file);
php 二维码生成类的更多相关文章
- QRCodeHelper 二维码生成
QRCodeHelper 二维码生成 using System; using System.Drawing; using ThoughtWorks.QRCode.Codec; using System ...
- C# 二维码生成 ( QRCoder )
二维码1.前言seaconch 最近在搞二维码方面的一些东西,所以接触了一些二维码相关,那么既然用过了就要有用过了的样子 其实关于二维码的文章真的多的数不胜数,有很多写的很认真,很好,但这就像是学习一 ...
- java生成二维码工具类
package com.runtime.extend.utils.CodeCreate; import com.google.zxing.*;import com.google.zxing.commo ...
- Java使用Zxing生成、解析二维码工具类
Zxing是Google提供的关于条码(一维码.二维码)的解析工具,提供了二维码的生成与解析的方法. 1.二维码的生成 (1).将Zxing-core.jar 包加入到classpath下. (2). ...
- Android 二维码 生成和识别(附Demo源码)
今天讲一下目前移动领域很常用的技术——二维码.现在大街小巷.各大网站都有二维码的踪迹,不管是IOS. Android.WP都有相关支持的软件.之前我就想了解二维码是如何工作,最近因为工作需要使用相关技 ...
- Android 二维码 生成和识别(转)
原博客地址 :http://www.cnblogs.com/weixing/archive/2013/08/28/3287120.html 还有几个写的也可以参考一下:http://www.itnos ...
- 二维码工具类 - QrcodeUtils.java
二维码工具类,提供多种生成二维码.解析二维码的方法,包括中间logo的二维码等方法. 源码如下:(点击下载 - QrcodeUtils.java.MatrixToImageWriterEx.java. ...
- android 二维码生成+扫描
android 二维码生成+扫描 1.在Android应用当中,很多时候都要用到二维码扫描,来避免让用户手动输入的麻烦. Google官方自己推出了一个二维码开源项目:ZXing库. 2.这里简单介绍 ...
- java利用Google Zxing实现 二维码生成与解析
1.引入zxing 2.使用下面两个类:QRCodeUtil.java和BufferedImageLuminanceSource.java 3.新建单元测试类 复制下面测试代码即可. 1.pom文件中 ...
随机推荐
- 短信猫编程的一些资料1(At指令发送短信)
现在正在做TC35的项目, 下面分享一下这几天在网上找到的资料: 手机 SMS PDU 格式参考手册 1.相关的GSM AT指令 与SMS有关的GSM AT指令(from GSM0 ...
- AngularJs练习Demo1
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- Mysql常用命令记录
-- 导出数据库: mysqldump -u user_name -p database_name > import_file.sql -- 执行脚本 source database.sql
- (一)CodeMirror - 基本应用
基本引用: <link rel="stylesheet" href="../lib/codemirror.css"> <script src= ...
- 鼠标悬停移除更换class
$("#xinl").mouseover(function() //鼠标悬停执行函数 { $(".xl").removeClass().addClass(&q ...
- 在Win8.1(64位)系统上安装Scrapy(python 2.7.7)
为了在win8.1上安装scrapy折腾了好久,最终安装成功,总结步骤如下: 下载安装Visual C++ 2008 redistributables 安装lxml-3.2.4.win-amd64-p ...
- 初识cross apply & outer apply
1. 2. 3.参考地址: http://blog.csdn.net/htl258/article/details/4537421
- HDU 3401 Trade(单调队列优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:炒股.第i天买入一股的价钱api,卖出一股的价钱bpi,最多买入asi股,最多卖出bsi股 ...
- [置顶] Android EditText/TextView使用SpannableString显示复合文本
在Android中EditText用于编辑文本,TextView用于显示文本,但是有时候我们需要对其中的文本进行样式等方面的设置.Android为我们提供了SpannableString类来对指定文本 ...
- Zoj3332-Strange Country II(有向竞赛图)
You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...