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 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 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 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 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'}