<?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 二维码生成类的更多相关文章

  1. QRCodeHelper 二维码生成

    QRCodeHelper 二维码生成 using System; using System.Drawing; using ThoughtWorks.QRCode.Codec; using System ...

  2. C# 二维码生成 ( QRCoder )

    二维码1.前言seaconch 最近在搞二维码方面的一些东西,所以接触了一些二维码相关,那么既然用过了就要有用过了的样子 其实关于二维码的文章真的多的数不胜数,有很多写的很认真,很好,但这就像是学习一 ...

  3. java生成二维码工具类

    package com.runtime.extend.utils.CodeCreate; import com.google.zxing.*;import com.google.zxing.commo ...

  4. Java使用Zxing生成、解析二维码工具类

    Zxing是Google提供的关于条码(一维码.二维码)的解析工具,提供了二维码的生成与解析的方法. 1.二维码的生成 (1).将Zxing-core.jar 包加入到classpath下. (2). ...

  5. Android 二维码 生成和识别(附Demo源码)

    今天讲一下目前移动领域很常用的技术——二维码.现在大街小巷.各大网站都有二维码的踪迹,不管是IOS. Android.WP都有相关支持的软件.之前我就想了解二维码是如何工作,最近因为工作需要使用相关技 ...

  6. Android 二维码 生成和识别(转)

    原博客地址 :http://www.cnblogs.com/weixing/archive/2013/08/28/3287120.html 还有几个写的也可以参考一下:http://www.itnos ...

  7. 二维码工具类 - QrcodeUtils.java

    二维码工具类,提供多种生成二维码.解析二维码的方法,包括中间logo的二维码等方法. 源码如下:(点击下载 - QrcodeUtils.java.MatrixToImageWriterEx.java. ...

  8. android 二维码生成+扫描

    android 二维码生成+扫描 1.在Android应用当中,很多时候都要用到二维码扫描,来避免让用户手动输入的麻烦. Google官方自己推出了一个二维码开源项目:ZXing库. 2.这里简单介绍 ...

  9. java利用Google Zxing实现 二维码生成与解析

    1.引入zxing 2.使用下面两个类:QRCodeUtil.java和BufferedImageLuminanceSource.java 3.新建单元测试类 复制下面测试代码即可. 1.pom文件中 ...

随机推荐

  1. hashtable 和dictionary

    hashtable 通过 key 和value 进行访问 不是 通过 索引访问 对类型没有强制规定 ,所以类型危险 容易出错 无效的key时 会返回空 dictionary 与hashtable 相区 ...

  2. myeclipse修改内存

    安装完成后,在安装目录有个config.ini文件,内容如下:-vmargs-Xms40m-Xmx256m Xms:初始化内存大小xmx:最大内存大小用编辑工具打开他,把Xms 和Xmx更改成自己需要 ...

  3. .net 开发定时执行的windows服务

    环境:win7+vs2010+Oracle11g+office2010(64位操作系统) 需求:开发定时执行的windows服务从数据库中查询数据下载到指定地址Excel中 一.添加新建项目——win ...

  4. 关于百度鹰眼中 xcode 7 编译报错问题

    请把 这个地方改为 YES 否则demo 不能运行

  5. iOS的触摸事件

    在iOS中不是任何对象都能处理事件,只有继承了UIResponder的对象才能接收并处理事件,我们称其为@''响应者对象''UIApplication,UIViewController,UIView都 ...

  6. hdu 2438

    Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...

  7. mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    从字面的意思上说:这个函数要被弃用,请使用 mysqlli 或者是 PDO 代替 然后就查手册发现没说,大家一定要查官方最新的手册

  8. CoreData (四)备

    监听NSFetchedResultsController 之前说过, NSFetchedResultsController是有两个重要的功能. 第一:NSFetchedResultsControlle ...

  9. CART剪枝

    与上篇文章中提到的ID3算法和C4.5算法类似,CART算法也是一种决策树分类算法.CART分类回归树算法的本质也是对数据进行分类的,最终数据的表现形式也是以树形的模式展现的,CART与ID3,C4. ...

  10. HttpAsyncClient 的简单使用

    下载地址:http://hc.apache.org/downloads.cgi 在NetBeans中导入以下jar文件: 1:一次请求: public static void oneReuest(){ ...