Esempio n. 1
0
def save_qrcode(text, img_type, path, name, qr_type_number, error_correct_level):
    # write qr code to filesystem
    if img_type not in QR_IMG_TYPES:
        raise ImageTypeException("can't generate QR Code, not a valid type")
    if not toolbox.string_has_content(text):
        raise ValueError("can't generate QR Code without proper string content")
    qr = QRCode(qr_type_number, error_correct_level)
    qr.addData(text)
    qr.make()
    im = qr.makeImage()
    qrcode_filename = name+img_type
    im.save(QR_FS_ROOT+qrcode_filename)
    return qrcode_filename
Esempio n. 2
0
 def create_qrcode_file(self, text, img_type, name):
     # write qr code to filesystem
     if img_type not in settings.QR_IMG_TYPES:
         raise ImageTypeException("can't generate QR Code, not a valid image type (determined by extension) " + settings.QR_IMG_TYPES)
     if not toolbox.string_has_content(text):
         raise ValueError("can't generate QR Code without proper string content")
     # determine the qrcode type based on amount of content to load
     content_length = len(text)
     if content_length in range(1, 5):
         qrtypenumber = 1   # [TODO] continue here once the data is clear
     qr = QRCode(self.qrtypenumber, self.eclevel)
     qr.addData(text)
     qr.make()
     im = qr.makeImage()
     qrcode_filename = name+img_type
     full_file_path = os.path.join(settings.QR_FS_ROOT, qrcode_filename)
     im.save(full_file_path)
     return qrcode_filename, full_file_path
 def create_qrcode_file(self, text, img_type, name):
     # write qr code to filesystem
     lid("create_qrcode_file start")
     if img_type not in settings.QR_IMG_TYPES:
         raise ImageTypeException("can't generate QR Code, not a valid image type (determined by extension) " + settings.QR_IMG_TYPES)
     if not toolbox.string_has_content(text):
         raise ValueError("can't generate QR Code without proper string content")
     # determine the qrcode type based on amount of content to load
     lid("looks like the image type check out ...")
     content_length = len(text)
     # [TODO] optimize best version determination, the best_fit method (called by default) of the QRCode lib is based on cathing DataOverflowErrors, determining version should be declarative lookup based
     qr = qrcode.QRCode(self.qrtypenumber, self.eclevel)
     qr.add_data(text)
     qr.make()
     im = qr.make_image()
     qrcode_filename = name+img_type
     full_file_path = os.path.join(settings.QR_FS_ROOT, qrcode_filename)
     im.save(full_file_path)
     lid("wrote file to filesystem: %s" % full_file_path)
     return qrcode_filename, full_file_path