class QRCode(object): def __init__(self, w, h, message, **kwargs): self.qrc = QRChart(w, h, **kwargs) self.qrc.add_data(message) def getPngImage(self, w, h, fgcol, bgcol): w = int(w) h = int(h) # img = Image.new('RGB', (w, h), bgcol) # d = ImageDraw.Draw(img) # for bx, bw in bars: # d.rectangle(((bx, 0), (bx+bw-1, h-1)), fgcol) # del d import urllib2 opener = urllib2.urlopen(self.qrc.get_url()) if opener.headers['content-type'] != 'image/png': raise Exception('Server responded with a ' \ 'content-type of %s' % opener.headers['content-type']) stream = opener.read() opener.close() img = Image.open(StringIO.StringIO(stream)) return img
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 qr_code(data, size=125): chart = QRChart(size, size) chart.add_data(data) chart.set_ec('H', 0) return {'qr_code': chart.get_url(), 'type': 'url' }
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 generate_qr_code(bird): # try / except here because we rely on an external service. try: from pygooglechart import QRChart # Create a 125x125 QR code chart chart = QRChart(125, 125) # Add the text string = 'BirdName: ' + bird.name + '\n Birthday: ' + bird.date_of_birth.__str__( ) + '\n URL: https://zongbird-db.lan.ini.uzh.ch' + bird.get_absolute_url( ) chart.add_data(string) # "Level H" error correction with a 0 pixel margin chart.set_ec('H', 0) # get url a = chart.get_url() return a except: return []
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 submit_job(request): #if request.method not in ["POST", "PUT"]: # return Http404() params = dict([item for item in request.REQUEST.items() if item[1]]) customer = next(iter(Customer.objects.filter(id=params["customer"])),\ None) if customer is None: return Http404() participant = next(iter(Participant.objects.filter(\ email=params["email"])),\ None) #if participant: # return Http404() participant = Participant.objects.create(customer=customer, first_name=params["first_name"], last_name=params["last_name"], email=params["email"], payload=params['payload']) participant.save() participant.code = generate_key() participant.save() # Create a 125x125 QR code chart chart = QRChart(250, 250) # Add the text chart.add_data(participant.code) # "Level H" error correction with a 0 pixel margin chart.set_ec('H', 0) # Download return HttpResponse(chart.get_url())
def __init__(self, w, h, message, **kwargs): self.qrc = QRChart(w, h, **kwargs) self.qrc.add_data(message)
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)
def qr_code(data, size=125): chart = QRChart(size, size) chart.add_data(data) chart.set_ec('H', 0) return {'qr_code': chart.get_url(), 'type': 'url'}