本文整理匯總了Python中qrcode.QRCode方法的典型用法代碼示例。如果您正苦於以下問題:Python qrcode.QRCode方法的具體用法?Python qrcode.QRCode怎麽用?Python qrcode.QRCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qrcode
的用法示例。
在下文中一共展示了qrcode.QRCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_qr_code
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def make_qr_code(message, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=4):
"""Return an in-memory SVG QR code containing the given message."""
# https://pypi.python.org/pypi/qrcode/5.3
# qrcode.constants.ERROR_CORRECT_M means about 15% or less errors can be corrected.
code = qrcode.QRCode(
version=1,
error_correction=error_correction,
box_size=box_size,
border=border,
)
code.add_data(message)
code.make(fit=True)
img = code.make_image(image_factory=SvgPathImage)
raw = BytesIO()
img.save(raw)
raw.flush()
return raw
示例2: make_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def make_qrcode(uuid, render_choice='browser'):
qr = qrcode.QRCode(
version=8,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=4,
border=4,
)
qr.add_data(JIKE_URI_SCHEME_FMT.format(**uuid))
qr.make()
render_choices = {
'browser': render2browser,
'terminal': render2terminal,
'viewer': render2viewer
}
assert render_choice in render_choices, 'Unsupported render choice.\nAvailable choices: browser, viewer, terminal'
render_choices[render_choice](qr)
示例3: generate_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def generate_qrcode(data):
"""Generate a QR Code.
Args:
data (str): Data.
"""
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=1,
)
qr.add_data(data.strip())
qr.make(fit=True)
img = qr.make_image(fill_color='black', back_color='white')
imcv = numpy.asarray(img.convert('L'))
cv2.imwrite('qrcode.png', imcv)
示例4: gen_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def gen_qrcode():
url = raw_input(''+T+'' + color.UNDERLINE + 'Website or text>' + color.END)
print ""+C+"Enter the name of the output file without the extension"
name = raw_input(''+T+'' + color.UNDERLINE + 'Output>' + color.END)
qr = qrcode.QRCode(5, error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data(url)
qr.make()
im = qr.make_image()
time.sleep(1)
qr_img_path = os.path.join(name + ".png")
if os.path.isfile(qr_img_path):
os.remove(qr_img_path)
# save the image out
im.save(qr_img_path, format='png')
# print that its been successful
print(""+G+"[!] " + color.UNDERLINE + "QRCode has been generated!" + color.END)
示例5: _showQRCodeImg
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def _showQRCodeImg(self, str):
if self.commandLineQRCode:
qrCode = QRCode('https://login.weixin.qq.com/l/' + self.uuid)
self._showCommandLineQRCode(qrCode.text(1))
else:
url = 'https://login.weixin.qq.com/qrcode/' + self.uuid
params = {
't': 'webwx',
'_': int(time.time())
}
data = self._post(url, params, False)
if data == '':
return
QRCODE_PATH = self._saveFile('qrcode.jpg', data, '_showQRCodeImg')
if str == 'win':
os.startfile(QRCODE_PATH)
elif str == 'macos':
subprocess.call(["open", QRCODE_PATH])
else:
return
示例6: test_print_ascii
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def test_print_ascii(self):
qr = qrcode.QRCode(border=0)
f = six.StringIO()
qr.print_ascii(out=f)
printed = f.getvalue()
f.close()
expected = u'\u2588\u2580\u2580\u2580\u2580\u2580\u2588'
self.assertEqual(printed[:len(expected)], expected)
f = six.StringIO()
f.isatty = lambda: True
qr.print_ascii(out=f, tty=True)
printed = f.getvalue()
f.close()
expected = (
u'\x1b[48;5;232m\x1b[38;5;255m' +
u'\xa0\u2584\u2584\u2584\u2584\u2584\xa0')
self.assertEqual(printed[:len(expected)], expected)
示例7: qr_code
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def qr_code(path):
if os.environ.get('WIFIONLY'):
return ''
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(short_base+path)
qr.make(fit=True)
img = io.BytesIO()
qr.make_image().save(img, 'PNG')
img.seek(0)
return send_file(img, mimetype='image/png')
示例8: genQrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def genQrcode(self):
content = self.content_edit.text()
try:
margin = int(self.margin_spinbox.text())
except:
margin = 0
size = int(self.size_combobox.currentText().split('*')[0])
qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=size//29,
border=margin)
qr.add_data(content)
self.qr_img = qr.make_image()
fp = io.BytesIO()
self.qr_img.save(fp, 'BMP')
qimg = QtGui.QImage()
qimg.loadFromData(fp.getvalue(), 'BMP')
qimg_pixmap = QtGui.QPixmap.fromImage(qimg)
self.show_label.setPixmap(qimg_pixmap)
示例9: make_base64_qr_code
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def make_base64_qr_code(bolt11):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=4,
border=4,
)
qr.add_data(bolt11)
qr.make(fit=True)
img = qr.make_image()
buffered = BytesIO()
img.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
return img_str
示例10: get_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def get_qrcode(user):
if not user.qrcode:
user.qrcode = pyotp.random_base32()
user.save()
file_name = str(aes.encrypt(user.qrcode), encoding='utf-8')
file = settings.QCODE_ROOT+'/'+file_name+'.png'
if not os.path.exists(file):
data = pyotp.totp.TOTP(user.qrcode).provisioning_uri(user.username, issuer_name="devEops")
qr = QRCode(
version=1,
error_correction=constants.ERROR_CORRECT_L,
box_size=6,
border=4,)
try:
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image()
img.save(file)
return '/media/qrcode/' + file_name + '.png'
except Exception as e:
return '/media/qrcode/' + file_name + '.png'
else:
return '/media/qrcode/' + file_name + '.png'
示例11: _render_now
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def _render_now(self):
if not self._interface.credstick:
qr_image = ['No QR Data']
colour_map = [None, 0, 0]
else:
#debug(); pdb.set_trace()
qr = qrcode.QRCode(
version=1,
box_size=4,
border=1,
)
#debug(); pdb.set_trace()
qr.add_data(self._interface.credstick.addressStr())
qr.make(fit=True)
qr_string = qr.print_ascii(string_only=True)
qr_image = qr_string.split('\n')
#debug(); pdb.set_trace()
colour_map = [[(Screen.COLOUR_GREEN, Screen.A_NORMAL, Screen.COLOUR_BLACK) for _ in range(self._width)]
for _ in range(self._height)]
return qr_image, colour_map
示例12: qr_code
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def qr_code(request, path):
data = (request.build_absolute_uri('/'+path) +
('?'+request.META['QUERY_STRING'] if request.META['QUERY_STRING'] else ''))
if len(data) > 256:
return HttpResponseBadRequest()
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=2,
)
qr.add_data(data)
qr.make(fit=True)
response = HttpResponse(content_type='image/png')
qr.make_image().save(response, 'PNG')
return response
示例13: test_alphanumeric_compression_maximum
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def test_alphanumeric_compression_maximum(self):
M = 4
N = 2000
data = ''.join([
random.choice(string.digits + string.ascii_letters) * M
for _ in range(N)])
data = data.encode('utf-8')
print(len(data)) # 10000
data = gzip.compress(data)
data = base64.b32encode(data)
print(len(data))
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make()
assert len(data) < 4296
assert True
示例14: setUp
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def setUp(self):
self.qr = qrcode.QRCode()
self.qr.add_data('JikeMetro')
示例15: qr_terminal_str
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import QRCode [as 別名]
def qr_terminal_str(data,version=None):
"""
:param data: qrcode data
:param version:1-40 or None
:return:
"""
if platform.system() == "Windows":
white_block = '▇'
black_block = ' '
new_line = '\n'
else:
white_block = '\033[0;37;47m '
black_block = '\033[0;37;40m '
new_line = '\033[0m\n'
qr = qrcode.QRCode(version)
qr.add_data(data)
if version:
qr.make()
else:
qr.make(fit=True)
output = white_block*(qr.modules_count+2) + new_line
for mn in qr.modules:
output += white_block
for m in mn:
if m:
output += black_block
else:
output += white_block
output += white_block + new_line
output += white_block*(qr.modules_count+2) + new_line
return output