Python qrcode.QRCode() Examples
The following are 30
code examples of qrcode.QRCode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
qrcode
, or try the search function
.
Example #1
Source File: donations.py From plugins with BSD 3-Clause "New" or "Revised" License | 10 votes |
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
Example #2
Source File: qr_code.py From Jike-Metro with MIT License | 7 votes |
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)
Example #3
Source File: donate.py From open-synthesis with GNU General Public License v3.0 | 7 votes |
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
Example #4
Source File: generate_qrcode.py From python-tools with MIT License | 7 votes |
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)
Example #5
Source File: main.py From c3nav-32c3 with Apache License 2.0 | 7 votes |
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')
Example #6
Source File: renderers.py From shadowlands with MIT License | 6 votes |
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
Example #7
Source File: views.py From c3nav with Apache License 2.0 | 6 votes |
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
Example #8
Source File: test_qrcode.py From teleport with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: test_qrcode.py From teleport with Apache License 2.0 | 6 votes |
def test_mode_8bit_newline(self): qr = qrcode.QRCode() qr.add_data('ABCDEFGHIJ1234567890\n', optimize=0) qr.make() self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)
Example #10
Source File: user.py From DevOps with GNU General Public License v2.0 | 6 votes |
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'
Example #11
Source File: test_limits.py From hermit with Apache License 2.0 | 6 votes |
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
Example #12
Source File: genQrcode.py From Tools with MIT License | 6 votes |
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)
Example #13
Source File: weixin.py From WeixinBot with Apache License 2.0 | 6 votes |
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
Example #14
Source File: qr.py From ITWSV with MIT License | 6 votes |
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)
Example #15
Source File: test_limits.py From hermit with Apache License 2.0 | 5 votes |
def test_binary_maximum(self): N = 2953 data = bytes(bytearray((random.getrandbits(8) for i in range(N)))) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(data) qr.make() assert True
Example #16
Source File: optical_codes.py From gdshelpers with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, origin, data, box_size, version=None, error_correction=ERROR_CORRECT_M, border=0, alignment='left-bottom'): self._qr_code = qrcode.QRCode(image_factory=ShapelyImageFactory, error_correction=error_correction, border=border, box_size=1, version=version) self._qr_code.add_data(data) self._alignment = Alignment(alignment) self.box_size = box_size self.origin = origin
Example #17
Source File: generate_fixture_images.py From hermit with Apache License 2.0 | 5 votes |
def generate_fixture_images(json_filename): filename_base = json_filename.split('.json')[0] with open(json_filename, 'r') as f: test_vector = json.load(f) data = json.dumps(test_vector['request']) data = data.encode('utf-8') data = gzip.compress(data) data = base64.b32encode(data) print(filename_base, "data length: ", len(data), " (must be <= 4296)") # qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4 ) qr.add_data(data) qr.make(fit=True) image = qr.make_image(fill_color="black", back_color="white") image.save(filename_base + '.png') #loaded_image = Image.open(filename_base + '.png') #decoded = pyzbar.decode(loaded_image) image_array = np.array(image.convert('RGB'))[:, :, ::-1].copy() numpy.save(filename_base + '.npy',image_array)
Example #18
Source File: test_limits.py From hermit with Apache License 2.0 | 5 votes |
def test_bits_overflow(self): N = 23550 data = 1 << N qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(data) with pytest.raises(qrcode.exceptions.DataOverflowError): qr.make() assert True
Example #19
Source File: displayer.py From hermit with Apache License 2.0 | 5 votes |
def create_qr_code_image(data: str) -> PilImage: qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(encode_qr_code_data(data)) qr.make(fit=True) return qr.make_image(fill_color="black", back_color="white")
Example #20
Source File: test_limits.py From hermit with Apache License 2.0 | 5 votes |
def test_bits_maximum(self): N = 23549 data = 1 << N qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(data) qr.make() assert True
Example #21
Source File: test_qrcode.py From FODI with GNU General Public License v3.0 | 5 votes |
def test_invalid_version(self): qr = qrcode.QRCode(version=41) self.assertRaises(ValueError, qr.make, fit=False)
Example #22
Source File: views.py From troupon with MIT License | 5 votes |
def generate_unique_code(self, deal, user): """ Generates Tickets for virtual deals Arguments: deal -- object representing the deal being purchased user -- object representing customer Returns: filename -- name of the file where QR code is stored id -- unique ID generated for this transaction """ # Converts utf8 to ascii strings because that is what UUID works with merchant_name = deal.advertiser.name.encode("utf8") deal_name = deal.advertiser.name.encode("utf8") username = user.username.encode("utf8") # Generates a unique code with python's UUID library # and embed in qrcode ticket_id = uuid.uuid5( uuid.NAMESPACE_DNS, merchant_name + deal_name + username ) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(ticket_id) qr.make(fit=True) img = qr.make_image() output = StringIO.StringIO() img.save(output, 'PNG') img = output.getvalue().encode("base64") output.close() return img, ticket_id
Example #23
Source File: weixin.py From WeixinBot with Apache License 2.0 | 5 votes |
def _str2qr(self, str): qr = qrcode.QRCode() qr.border = 1 qr.add_data(str) mat = qr.get_matrix() self._printQR(mat) # qr.print_tty() or qr.print_ascii()
Example #24
Source File: utils.py From django-htk with MIT License | 5 votes |
def make_qr_code_image( data='', version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=4 ): """Generates a QR Code image Documentation: https://pypi.python.org/pypi/qrcode 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). A shorthand with all of the defaults is possible: qrcode.make(data) """ qr = qrcode.QRCode( version=version, error_correction=error_correction, box_size=box_size, border=border ) qr.add_data(data) qr.make(fit=True) img = qr.make_image() return img
Example #25
Source File: wallet_runnable.py From wallets with Apache License 2.0 | 5 votes |
def make_QR(wallet): print(divider) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4, ) qr.add_data(f"{wallet.get_new_puzzlehash()}") qr.make(fit=True) img = qr.make_image() fn = input("Input file name: ") img.save(f"{fn}.jpg") print(f"QR code created in '{fn}.jpg'")
Example #26
Source File: test_nubank_client.py From pynubank with MIT License | 5 votes |
def test_get_qr_code(monkeypatch): monkeypatch.setattr(Discovery, '_update_proxy_urls', fake_update_proxy) client = Nubank() uid, qr = client.get_qr_code() assert uid != '' assert isinstance(qr, QRCode)
Example #27
Source File: nubank.py From pynubank with MIT License | 5 votes |
def get_qr_code(self) -> Tuple[str, QRCode]: content = str(uuid.uuid4()) qr = QRCode() qr.add_data(content) return content, qr
Example #28
Source File: lntxbot.py From LightningATM with MIT License | 5 votes |
def generate_lnurl_qr(lnurl): """Generate an lnurl qr code from a lnurl """ lnurlqr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=2, border=1, ) lnurlqr.add_data(lnurl.upper()) logger.info("LNURL QR code generated") return lnurlqr.make_image()
Example #29
Source File: content_qrcodegen.py From sketal with MIT License | 5 votes |
def process_message(self, msg): command, text = self.parse_message(msg, full=True) if not text: await msg.answer('Введите слова или ссылку чтобы сгенерировать QR код') qr = qrcode.QRCode( error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(text) try: result = await self.run_in_executor(lambda: qr.make(fit=True)) except DataOverflowError: return await msg.answer('Слишком длинное сообщение!') img = await self.run_in_executor(qr.make_image) if not img: return await msg.answer("Произошла ошибка!") buf = io.BytesIO() img.save(buf, format='png') buf.seek(0) result = await upload_photo(self.api, buf) return await msg.answer(f'Ваш QR код, с данными: \n "{text}"', attachment=str(result))
Example #30
Source File: optical_codes.py From gdshelpers with GNU Lesser General Public License v3.0 | 5 votes |
def _example(): qr_code = QRCode([0, 0], 'A0.0', 1.0, version=1, error_correction=QRCode.ERROR_CORRECT_M) from gdshelpers.geometry.chip import Cell device = Cell('test') device.add_to_layer(1, qr_code) device.show() chip = Cell('optical_codes') chip.add_cell(device) chip.start_viewer() chip.save()