qrcode 4.0.4 : Python Package Index
qrcode 4.0.4 : Python Package Index
qrcode 4.0.4
QR Code image generator
This module uses image libraries, Python Imaging Library (PIL) by default, to generate QR Codes.
It is recommended to use the pillow fork rather than PIL itself.
What is a QR Code?
A Quick Response code is a two-dimensional pictographic code used for its fast readability and comparatively large storage capacity. The code consists of black modules arranged in a square pattern on a white background. The information encoded can be made up of any kind of data (e.g., binary, alphanumeric, or Kanji symbols)
Usage
From the command line, use the installed qr script:
qr "Some text" > test.pngOr in Python, use the make shortcut function:
import qrcode
img = qrcode.make('Some data here')Advanced Usage
For more control, use the QRCode class. For example:
import qrcode
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data('Some data')
qr.make(fit=True) img = qr.make_image()The version parameter is an integer from 1 to 40 that controls the size of the QR Code (the smallest, version 1, is a 21x21 matrix). Set to None and use the fit parameter when making the code to determine this automatically.
The error_correction parameter controls the error correction used for the QR Code. The following four constants are made available on the qrcode package:
- ERROR_CORRECT_L
- About 7% or less errors can be corrected.
- ERROR_CORRECT_M (default)
- About 15% or less errors can be corrected.
- ERROR_CORRECT_Q
- About 25% or less errors can be corrected.
- ERROR_CORRECT_H.
- About 30% or less errors can be corrected.
The box_size parameter controls how many pixels each "box" of the QR code is.
The border parameter controls how many boxes thick the border should be (the default is 4, which is the minimum according to the specs).
Other image factories
You can encode as SVG, or use a new pure Python image processor to encode to PNG images.
The Python examples below use the make shortcut. The same image_factory keyword argument is a valid option for the QRCode class for more advanced usage.
SVG
On Python 2.6 must install lxml since the older xml.etree.ElementTree version can not be used to create SVG images.
You can create the entire SVG or an SVG fragment. When building an entire SVG image, you can use the factory that combines as a path (recommended, and default for the script) or a factory that creates a simple set of rectangles.
From your command line:
qr --factory=svg-path "Some text" > test.svg
qr --factory=svg "Some text" > test.svg
qr --factory=svg-fragment "Some text" > test.svgOr in Python:
import qrcode
import qrcode.image.svg if method == 'basic':
# Simple factory, just a set of rects.
factory = qrcode.image.svg.SvgImage
elif method == 'fragment':
# Fragment factory (also just a set of rects)
factory = qrcode.image.svg.SvgFragmentImage
else:
# Combined path factory, fixes white space that may occur when zooming
factory = qrcode.image.svg.SvgPathImage img = qrcode.make('Some data here', image_factory=factory)Two other related factories are available that work the same, but also fill the background of the SVG with white:
qrcode.image.svg.SvgFillImage
qrcode.image.svg.SvgPathFillImagePure Python PNG
Install the following two packages:
pip install git+git://github.com/ojii/pymaging.git#egg=pymaging
pip install git+git://github.com/ojii/pymaging-png.git#egg=pymaging-pngFrom your command line:
qr --factory=pymaging "Some text" > test.pngOr in Python:
import qrcode
from qrcode.image.pure import PymagingImage
img = qrcode.make('Some data here', image_factory=PymagingImage)
qrcode 4.0.4 : Python Package Index的更多相关文章
- Ghost.py 0.1b3 : Python Package Index
Ghost.py 0.1b3 : Python Package Index Ghost.py 0.1b3 Download Ghost.py-0.1b3.tar.gz Webkit based web ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- bottle-session 0.3 : Python Package Index
bottle-session 0.3 : Python Package Index bottle-session 0.3
- bottle-session 0.2 : Python Package Index
bottle-session 0.2 : Python Package Index bottle-session 0.2 Download bottle-session-0.2.tar.gz Redi ...
- django-cookieless 0.7 : Python Package Index
django-cookieless 0.7 : Python Package Index django-cookieless 0.7 Download django-cookieless-0.7.ta ...
- graphterm 0.40.1 : Python Package Index
graphterm 0.40.1 : Python Package Index graphterm 0.40.1 Downloads ↓ A Graphical Terminal Interface ...
- Beaker 1.6.4 : Python Package Index
Beaker 1.6.4 : Python Package Index Beaker 1.6.4 Download Beaker-1.6.4.tar.gz A Session and Caching ...
- Install OpenCV 3.0 and Python 2.7+ on OSX
http://www.pyimagesearch.com/2015/06/15/install-OpenCV-3-0-and-Python-2-7-on-osx/ As I mentioned las ...
- Install OpenCV 3.0 and Python 2.7+ on Ubuntu
为了防止原文消失或者被墙,转载留个底,最好还是去看原贴,因为随着版本变化,原贴是有人维护升级的 http://www.pyimagesearch.com/2015/06/22/install-Open ...
随机推荐
- 【JAVA】修改项目包名
从最后一层开始修改,一步步往上递增修改.
- win7如何快速设置开机启动项?
添加开机启动项方法: 找到windows开始菜单->所有程序->启动,右键打开, 进入C:\Users\Ocean\AppData\Roaming\Microsoft\Windows\St ...
- json对象的操作,json工具
项目中经常用到json,现在把写了几个js函数,用来获取json对象或者json字符串的长度,以及获取其的key值,value值,并且返回. 这样以后可以直接拿来用,可以省去不少麻烦,也方便以后查看. ...
- 重新生成IE02
procedure ReBuild_IE02( pi_aac001 in number, po_fhz out varchar2, po_msg out varchar2) is type typ_t ...
- QT学习 之 QwtPlot(数学绘图)
QT对于统计图像.函数图像等的绘制是没有相关组件的帮助的,只有利用手工绘制图片. QwtPlot是用来绘制二维图像的widget,继承自QFrame 和 QwtPlotDict.不过严格的说来,它只是 ...
- VC6中创建Qt工程的创建
文章来源:http://blog.sina.com.cn/s/blog_64d015c10100sf1o.html 本文主要介绍怎么创建可以在VC6中编译的QT工程.本文所采用环境为VC++6.0+Q ...
- nginx自动切割访问日志
Web 访问日志 (access_log) 记录了所有外部客户端对Web服务器的访问行为,包含了客户端IP,访问日期,访问的URL资源,服务器返回的HTTP状态码等重要信息. 一条典型的Web访问日志 ...
- [移动网关]2G环境下资源下载有一定概率失败,客户端日志显示收到403错误
2G环境下资源下载有一定概率失败,客户端日志显示收到403错误 问题现象: 测试同学在使用联通号码在移动网络环境下,访问连接得到的response_code出现是403,导致资源读取失败表情显示异常. ...
- cmake 学习笔记(三)
转自:http://blog.csdn.net/dbzhang800/article/details/6329314 接前面的 Cmake学习笔记(一) 与 Cmake学习笔记(二) 继续学习 cma ...
- Tomcat7 + JRebel6.3.0 + IntelliJ idea 热部署配置过程+错误分析
以前使用Tomcat的时候直接就可以热部署,现在换了一个使用Spring框架的项目突然就不能热部署了. 网上说在tomcat里conf/context.xml中加入 <Context antiJ ...