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文件中 ...
随机推荐
- F# 越用越喜欢
F# 越用越喜欢 最近由于需要,把遗忘了几年的F#又捡了起来.说捡了起来,倒不如说是从头学习,原来学的早已经忘了!所谓学过,只不过看过一本<F# 语言程序设计> (郑宇军 凌海风 编著 - ...
- 《第一行代码》学习笔记15-UI(4)
1.ListView允许用户通过手指上下滑动的方式将屏幕外的数据滚动到屏幕内,同时屏幕上原有的数据则会滚动出屏幕. 2.数组中的数据无法直接传递给ListView,得借助适配器来完成.此处使用Arra ...
- C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断
1.DataGridViewCheckBoxColumn CheckBox是否选中 在判断DataGridView中CheckBox选中列的时候,用DataGridViewRow.Cells[0].F ...
- SQL 经典练习
SQL 基础练习 CREATE TABLE STUDENT(SNO VARCHAR(3) NOT NULL, SNAME VARCHAR(4) NOT NULL,SSEX VARCHAR(2) NOT ...
- hdu Phone List
Problem Description Given a list of phone numbers, determine if it is consistent in the sense that n ...
- QT5-控件-QDateEdit 和 日期类QDate
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDate> #inclu ...
- Mac添加或修改环境变量
方式1. 终端添加或修改 命令:pico, vim等 方式:pico .bash_profile 方式2. 文本方式添加或修改 1)打开 touch ~/.bash_profile open -t ~ ...
- 编译Boost 详细步骤
vs2008编译boost [一.Boost库的介绍] Boost库是一个经过千锤百炼.可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一. Boost库由C++标准委员会 ...
- Hdu1096
#include <stdio.h> int main() { int T,n; ; while(scanf("%d",&T)!=EOF){ while(sca ...
- httpcomponents-client-4.3.6 HttpPost的简单使用
/** * httpcomponents-client-4.3.6 * @author y */ public class HttpUtil { public static String httpPo ...