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 ...
随机推荐
- python编写工具及配置(notepad++)
学长跟我说老师实验室里用的ide是pycharm,我用了一天,整体还行,就是加载速度太慢,可是第二天用的时候就卡的想让人骂街,cpu占有率趋近100%,电脑配置不高,我寻思不能因为这个就马上换电脑吧, ...
- JavaSE学习总结第06天_Java语言基础2 & 面向对象1
06.01 二维数组概述和格式1的讲解 二维数组概述:二维数组其实就是一个元素为一维数组的数组 格式1:数据类型[][] 变量名 = new 数据类型[m][n]; m表示这个二维数组有多少个一维 ...
- MongoDB shell常用命令
Shell操作数据库: 1. 超级用户相关: 1. #进入数据库admin use admin 2. #增加或修改用户密码 db.addUser('name','pwd') 3. #查看用户列表 d ...
- 添加站点图标: 为SAE上的WordPress站点添加自己的Favicon
由于插件 Jetpack的"添加站点图标"功能有问题, 无法从本地上传ico文件到SAE的Storage. 因此需要手动添加站点图标. Step 1: 制作或下载自己的ico文件, ...
- python命令行解析工具argparse模块【4】
上一节我们讲解了add_argument()方法,这一节我们将学习parse_args()方法. parse_args()方法的作用是解析命令行参数,并返回解析之后的 ...
- 织梦dedeCMS|系统基本配置标签
站点根网址: {dede:global.cfg_basehost/}调出网站的名称: {dede:field.title/}-{dede:global.cfg_webname/} 网站 ...
- 我的Python成长之路---第六天---Python基础(18)---2016年2月20日(晴)
os模块 提供对操作系统进行调用的接口 >>> import os >>> os.getcwd() # 获取当前工作目录,类似linux的pwd命令 '/data/ ...
- Windows Phone 8初学者开发—第13部分:设置LongListSelector中磁贴的样式
原文 Windows Phone 8初学者开发—第13部分:设置LongListSelector中磁贴的样式 第13部分:设置LongListSelector中磁贴的样式 原文地址: http://c ...
- 修改MojoWeixin 只保留用户name 取消群昵称
<pre name="code" class="python"> if($msg->type eq "friend_message& ...
- NOIP2015
现在来总结一下. 斗地主 这题的题目描述感觉不太清晰,当时有很多人去问,但都没有得到任何回应.好吧,虽然我也是似懂非懂,但是就算看清楚了题目又能怎么样呢. 首先这题只能够搜索吧,或者说是DP,不过有很 ...