def get_qrcode(data): """ Return a QR Code PNG (binary data) """ height = width = 250 code = QRChart(height, width) code.set_ec('L', 0) # "Level L" error correction with a 0 pixel margin code.add_data(data) with get_temp_file() as (__, fname): code.download(fname) with open(fname, "rb") as f: png_data = f.read() return png_data
def hello(): # Create a 250x250 QR chart chart = QRChart(250, 250) # Add the text chart.add_data('Hello, World!') # "Level H" error correction with a 0 pixel margin chart.set_ec('H', 0) # Download chart.download('qr-hello.png')
def get_qr_code_from_google(): from pygooglechart import QRChart # Create a AxA QR code chart chart = QRChart(126, 126) # Add the text chart.add_data('ID:1234|Info: foobar') # "Level H" error correction with a 0 pixel margin chart.set_ec('H', 0) # Download chart.download('1.png')
def parse_data(data, out_prefix): chart = QRChart(SIZE, SIZE) chart.add_data(data.strip()) chart.set_ec('H', 0) out_fmt = out_prefix + '_{:03d}.png' count = 0 out_file = out_fmt.format(count) while os.path.exists(out_fmt.format(count)): count += 1 out_file = out_fmt.format(count) print 'Saving {}'.format(out_file) chart.download(out_file.format(count))
def createVCard(self, data): try: logging.debug("In create vCard") chart = QRChart(HEIGHT, WIDTH) templateData = '' for k, v in data.items(): templateData = self._templateData.replace('{%s}' % k, v) self._templateData = templateData match = re.sub(r'{\w*\w}', '', templateData) chart.add_data(match) chart.set_ec('H', 0) uid = uuid.uuid1() filePath = '%s/../static/cache/%s.png' % (os.path.dirname(__file__), uid) logging.debug("Creating image: " + filePath) chart.download(filePath) return uid except ex: logging.debug('Unhandled exception') logging.exception('Unhandled exception')
def create_qrcode_image(self): chart = QRChart(SHORTIM_QRCODE_SIZE, SHORTIM_QRCODE_SIZE) chart.add_data(self.get_short_full_url()) chart.set_ec('L', 0) chart.download(self.get_qrcode_path())
def doQr(text,fichier): chart = QRChart(125,125) chart.add_data(text) chart.set_ec('H',0) chart.download(fichier)