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 ...
随机推荐
- Axure使用
(一) Axure rp的界面 1-主菜单工具栏 大部分类似office软件,不做详细解释,鼠标移到按钮上都有对应的提示. 2-主操作界面 绘制产品原型的操作区域,所有的用到的元件都拖到该区域. 3 ...
- 什么是DNS劫持和DNS污染?
什么是DNS劫持和DNS污染? http://blogread.cn/it/article/7758?f=weekly 说明 我们知道,某些网络运营商为了某些目的,对 DNS 进行了某些操作,导致使用 ...
- Map接口的学习
接口Map<K, V> 一.Map功能 1.添加 put(K key, V value) putAll(Map<? extends K, ? extends V>); 2.删除 ...
- unix IO笔记
一.IO与文件映射 1.IO的共享与效率 read与write其中数据缓冲的大小 读取数据的缓冲:getpagesize 2.定位与定位读取(随机读取) read与write在操作的时候,自动移动读取 ...
- MacOS + Linux + Nginx
Asp.Net Core 发布和部署( MacOS + Linux + Nginx ) 前言 在上篇文章中,主要介绍了 Dotnet Core Run 命令,这篇文章主要是讲解如何在Linux中,对 ...
- VC程序快速删除自己(可能做升级程序的时候有用)
项目一般都会带有卸载程序,如果这个程序是自己来做的话,在调用完卸载程序后需要删除自己的所有文件,在Google了好久终于找到一些相关信息,一般只能删除一个文件,经过自己的处理,可以删除文件夹下面所有内 ...
- Java调用Python脚本
今天遇到Java调用一个Python脚本的问题,纠结了大半天,遇到各种问题.网上搜索的大部分都是用jython,但是我想要调用的python脚本里有import urllib,这个urllib也不是什 ...
- boost::thread用法
最近在做一个消息中间件里面涉及到多线程编程,由于跨平台的原因我采用了boost线程库.在创建线程时遇到了几种线程创建方式现总结如下: 首先看看boost::thread的构造函数吧,boost::th ...
- 1298 The Hardest Problem Ever
题目链接:http://poj.org/problem?id=1298 思路分析:水题,字符偏移求解,注意字符串输入问题即可. 代码如下: #include <iostream> #inc ...
- 奔小康赚大钱(km)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...