簡體   English   中英

在Python 3.6中使用qrcode將批處理QR碼創建為圖像

[英]Using qrcode in Python 3.6 to create batches of QR Codes as images

我在Windows 10機器上運行Python 3.6,並想直接從python創建成批的QR碼作為PNG。 我將使用qrcode創建100到200個單獨的QR碼批次。 然后,這些圖像將用於郵件合並中以創建單個文檔。 我可以使用qr.exe腳本創建單個圖像,但無法在Python中創建QR碼PNG。

在閱讀有關qrcode的文檔時,我遇到了一些麻煩,無法使“ Pure Python PNG”正常工作( https://github.com/lincolnloop/python-qrcode/blob/master/README.rst )。

具體來說,當我嘗試在命令提示符下使用PIP安裝pymaging時

pip安裝git + git://github.com/ojii/pymaging.git#egg=pymaging pip安裝git + git://github.com/ojii/pymaging-png.git#egg=pymaging-png

我得到以下報告

從git + git://githumb.com/ojii/pymaging.git#egg=pymaging收集pymaging將git://github.com/ojii/pymaging.git克隆到c:\\ Users \\ B \\ AppDataq \\ Local \\ Temp \\ PIP-集結jioh63js \\ pymaging

然后我得到以下錯誤

錯誤[WinError 2]執行命令git clone -q git://github.com/ojii/pymaging.git c:\\ Users \\ B \\ AppDataq \\ Local \\ Temp \\ pip-build-jioh63js時,系統找不到指定的文件\\ pymaging找不到命令'git'

我查看了temp文件夾,沒有看到任何pip *文件夾。 您對如何安裝pymaging有任何建議嗎?

-更新-

一旦安裝了git,就可以從git的bash運行命令,並安裝pymaging。

在Python 3中創建大量QR碼作為圖像的文檔的文檔有點小,特別是編寫實際圖像文件的最后步驟( 請參閱qrcode 5.3文檔 ),所以我想分享一些我修改並可以正常工作的代碼。 Python 2.7的原始代碼來自prasopensource的博客 以下是我為Python 3.6創建的腳本。

import qrcode, os.path
print('What is the name of the file containing the data for the QR codes?')
fname = input().strip()
file = open(fname, "r")
print()
for x in file:
    x = x.rstrip()
    qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=10,border=4,)
    qr.add_data(x)
    qr.make(fit=True)
    img = qr.make_image()
    file_name = x + ".png"
    print('Saving %s' % file_name)
    image_file = open(file_name, "w")
    img.save(file_name)
    image_file.close()
file.close()

# INFORMATION ABOUT QRCode SETTINGS
#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).

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM