python qrcode 库的使用
生活随笔
收集整理的這篇文章主要介紹了
python qrcode 库的使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
python qrcode 庫的使用首先要安裝PIL圖形處理庫(安裝方法:點擊打開鏈接)
qrcode的使用方法:
命令行生成二維碼(二維碼內(nèi)容為Some text)
qr "Some text" > test.png 簡單的python程序生成二維碼 #!/usr/bin/env python #coding=utf-8 import qrcodeimg = qrcode.make("Some text"); img.save("test,png"); python程序生成二維碼的高級使用方法 #!/usr/bin/env python #coding=utf-8import qrcode qr = qrcode.QRCode(version = 1, error_correction = qrcode.constants.ERROR_CORRECT_L, box_size = 0, border=1); qr.add_data("Some text"); qr.make(fit = True); img = qr.make_image(); img.save("Test.png");version (值從 1-40, 最小的是1,用21 x 21像素表示), 填None 的話電腦會給你設置一個合適的像素 error_correction ERROR_CORRECT_L/ERROR_CORRECT_M/ERROR_CORRECT_Q/ERROR_CORRECT_H 7%/15%/25%/30%的容錯率 box_size 設置每個方塊二維碼的像素 border 設置二維碼的邊界命令行python程序生成失量圖
qr --factory=svg-path "Some test" > test.svg qr --factory=svg "Some test" > test.svg qr --factory=svg-fragment "Some test" > test.svgpython代碼生成失量圖
#!/usr/bin/env python # coding=utf-8 import qrcode import qrcode.image.svgmethod = raw_input()if method == 'basic':factory = qrcode.image.svg.SvgImage elif method == 'fragment':factory = qrcode.image.svg.SvgFragmentImage else:factory = qrcode.image.svg.SvgPathImageimg = qrcode.make("Some text", image_factory=factory) img.save("test.svg");qrcode.image.svg.SaveFillImage/qrcode.image.svg.SavePathFillImage 都能實現(xiàn)和 qrcode.image.svg.SavePathImage 一樣的功能Pure Python PNG
安裝下面的兩個包:
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.pngPython 程序生成二維碼 import qrcode from qrcode.image.pure import PymagingImage img = qrcode.make('Some data here', image_factory=PymagingImage) Python代碼生成的失量圖和png圖片的比較(左邊失量圖,右邊png圖)
總結
以上是生活随笔為你收集整理的python qrcode 库的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML5七夕情人节表白代码_浪漫烟花表
- 下一篇: 2019年总结回顾 ~ 开心!评上CSD