日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python qrcode 库的使用

發布時間:2024/3/12 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python qrcode 库的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python qrcode 庫的使用首先要安裝PIL圖形處理庫(安裝方法:點擊打開鏈接)

qrcode的使用方法:

命令行生成二維碼(二維碼內容為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.svg

python代碼生成失量圖

#!/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 都能實現和 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.png
Python 程序生成二維碼

import qrcode from qrcode.image.pure import PymagingImage img = qrcode.make('Some data here', image_factory=PymagingImage) Python代碼生成的失量圖和png圖片的比較(左邊失量圖,右邊png圖)


總結

以上是生活随笔為你收集整理的python qrcode 库的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。