예제 #1
0
    def qrcode(self, text, x, y, max_size, clear=False):
        return
        if not IMAGE:
            raise RuntimeError(
                "PIL is required to display QR codes, but it is not installed on your system."
            )

        code = qr.QRCode(1, qr.QRErrorCorrectLevel.L)
        code.addData(text)
        code.make()
        image = code.makeImage()
        width, height = image.size

        if width > max_size or height > max_size:
            for i in range(max_size):
                size = max_size - i
                if divmod(width, size)[1] == 0:
                    image = image.resize((size, size))
                    break

        image.save("qr.png")

        self.image(image,
                   x,
                   y,
                   condition='red > 100 or green > 100 or blue > 100',
                   clear=clear)

        if self.auto_commit:
            self.display.commit()
예제 #2
0
def makeQR(data_string, path, level=2, boxSize=4, color=(0, 0, 0, 255)):
    quality = {
        1: PyQRNative.QRErrorCorrectLevel.L,
        2: PyQRNative.QRErrorCorrectLevel.M,
        3: PyQRNative.QRErrorCorrectLevel.Q,
        4: PyQRNative.QRErrorCorrectLevel.H
    }
    size = 1
    while 1:
        try:
            print "trying size %s" % size
            q = PyQRNative.QRCode(size, quality[level], boxSize=boxSize)
            q.addData(data_string)
            q.make()
            im = q.makeImage()
            img = im.convert("RGBA")
            #Color
            if color != (0, 0, 0, 255):
                print "Given color is not black"

                pixdata = img.load()

                # If pixel is black change to desired color.
                for y in xrange(img.size[1]):
                    for x in xrange(img.size[0]):
                        if pixdata[x, y] == (0, 0, 0, 255):
                            pixdata[x, y] = color

            img.save(path, format="png")
            break
        except TypeError as te:
            print "failed increasing size"
            print str(te)
            size += 1
예제 #3
0
파일: test.py 프로젝트: xqat/pyqrnative
    def setUp(self):
        self.data = "Test string"
        
        # Create image
        qr = PyQRNative.QRCode(4, PyQRNative.QRErrorCorrectLevel.L)
        qr.addData(self.data)
        qr.make()
        self.image = qr.makeImage()

        # Set up scanner
        self.scanner = zbar.ImageScanner()
        self.scanner.parse_config('enable')
예제 #4
0
    def onUsePyQR(self, event):
        """
        http://code.google.com/p/pyqrnative/
        """
        qr = PyQRNative.QRCode(20, PyQRNative.QRErrorCorrectLevel.L)
        qr.addData(self.qrDataTxt.GetValue())
        qr.make()
        im = qr.makeImage()

        qr_file = os.path.join(self.defaultLocation,
                               self.qrPhotoTxt.GetValue() + ".jpg")
        img_file = open(qr_file, 'wb')
        im.save(img_file, 'JPEG')
        img_file.close()
        self.showQRCode(qr_file)
예제 #5
0
    def generate_qr_image(self):
        """ Use pyqrnative to build a qr image, and save to disk.
        """
        pyqr = PyQRNative.QRCode(4, PyQRNative.QRErrorCorrectLevel.H)

        pyqr.addData(self.link_txt)
        pyqr.make()
        qr_image = pyqr.makeImage()

        # Resize the image so it first nicely on the graphic
        img_file = open("%s/../resources/temp_qr.png" \
                        % self.dir_name, "wb")
        qr_image = qr_image.resize((320, 320))
        qr_image.save(img_file, 'PNG')
        img_file.close()
예제 #6
0
def makeQR(text, dest):
    size = 3
    # this function mostly taken from http://www.blog.pythonlibrary.org/2012/05/18/creating-qr-codes-with-python/
    for size in range(1, 5):
        try:
            qr = PyQRNative.QRCode(size, PyQRNative.QRErrorCorrectLevel.M)
            qr.addData(text)
            qr.make()
        except TypeError:
            # erhöhe size, weil URL zu lang für gewählte size
            if size == 5:
                raise Exception(
                    "URL zu lang - size in makeQR erhöhen oder besser URL kürzen"
                )
            continue
        break
    im = qr.makeImage()
    img_file = open(dest, 'wb')
    im.save(img_file, 'PNG')
    img_file.close()