1.1 用Python来生成二维码很简单,可以看 qrcode 这个包:
pip install qrcode
qrcode 依赖 Image 这个包:
pip install Image
1.2 安装后就可以使用了,这个程序带了一个 qr 命令:
qr 'http://www.ziqiangxuetang.com' > test.png
1.3 下面我们看一下如何在 代码 中使用
import qrcode
img = qrcode.make('http://www.tuweizhong.com')
# img <qrcode.image.pil.PilImage object at 0x1044ed9d0>
with open('test.png', 'wb') as f:
img.save(f)
安装:
pip install git+git://github.com/ojii/pymaging.git#egg=pymaging
pip install git+git://github.com/ojii/pymaging-png.git#egg=pymaging-png
使用方法大致相同,命令行上:
qr --factory=pymaging "Some text" > test.png
Python中调用:
import qrcode
from qrcode.image.pure import PymagingImage
img = qrcode.make('Some data here', image_factory=PymagingImage)