Esempio n. 1
0
def get_qrcode(ver, ecl, str, save_place):
    # Data Coding
    ver, data_codewords = data.encode(ver, ecl, str)

    # Error Correction Coding
    ecc = ECC.encode(ver, ecl, data_codewords)
    
    # Structure final bits
    final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)
    
    # Get the QR Matrix
    qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)
        
    # Draw the picture and Save it, then return the real ver and the absolute name
    return ver, draw.draw_qrcode(save_place, qrmatrix)
Esempio n. 2
0
def get_qrcode(ver, ecl, str):
    # Data Coding
    ver, data_codewords = data.encode(ver, ecl, str)

    # Error Correction Coding
    ecc = ECC.encode(ver, ecl, data_codewords)

    # Structure final bits
    final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)

    # Get the QR Matrix
    qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)

    # Draw the picture and Save it, then return the real ver and the absolute name
    return ver, draw.draw_qrcode(qrmatrix)
Esempio n. 3
0
def get_qrcode(ver: object, ecl: object, string: str, scale: int,
               color: tuple) -> object:
    # Data Coding
    ver, data_codewords = data.encode(ver, ecl, string)

    # Error Correction Coding
    ecc = ECC.encode(ver, ecl, data_codewords)

    # Structure final bits
    final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)

    # Get the QR Matrix
    qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)

    # Draw the picture and Save it, then return the real ver and the absolute name
    return ver, draw.draw_qrcode(qrmatrix, scale, color)
Esempio n. 4
0
def get_qrcode(ver, ecl, str, save_place):
    # ver == 0: default that is depending on str and ecl
    if ver not in range(41):
        print('WARNING: Version Error! Please choose a version from 0 to 40!')
    elif ecl not in 'LMQH':
        print('WARNING: Level Error! Please choose one of L,M,Q,H!')
    elif any(i not in supported_chars for i in str):
        print('WARNING: Input Error! Some characters are not supported.')
    else:
        # Data Coding
        ver, data_codewords = data.encode(ver, ecl, str)

        # Error Correction Coding
        ecc = ECC.encode(ver, ecl, data_codewords)

        # Structure final bits
        final_bits = structure.structure_final_bits(ver, ecl, data_codewords,
                                                    ecc)

        # Get the QR Matrix
        qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)

        # Draw the picture and Save it, then return the real ver and the absolute name
        return ver, draw.draw_qrcode(save_place, qrmatrix)
Esempio n. 5
0
def generate(text: str, version: int = 1, level: str = 'H', scale: int = 1,
             color: tuple = (0, 0, 0), image: object = None,
             imagesize: tuple = (10, 10), gold: object = None) -> object:
    # Data Coding
    version, data_codewords = data.encode(version, level, text)

    # Error Correction Coding
    ecc = ECC.encode(version, level, data_codewords)

    # Structure final bits
    final_bits = structure.structure_final_bits(version, level, data_codewords, ecc)

    # Get the QR Matrix
    qrmatrix = matrix.get_qrmatrix(version, level, final_bits)

    unit_len = 4 * scale
    x = y = 0
    qr = Image.new('RGBA', [len(qrmatrix) * unit_len] * 2, 0)

    # Gold source
    if gold == 'tile':
        tile = Image.open('gold-dark.jpg')
        tile = tile.resize(qr.size, Image.ANTIALIAS).convert('RGBA')

    for line in qrmatrix:
        for module in line:
            if module:
                if gold == 'tile':
                    for i in range(unit_len):
                        for j in range(unit_len):
                            coordinate = a, b = x + i, y + j
                            pixelcolor = tile.getpixel(coordinate)
                            qr.putpixel((x + i, y + j), pixelcolor)
                else:
                    draw_a_color_unit(qr, x, y, unit_len, 0, color)
            else:
                draw_a_color_unit(qr, x, y, unit_len, 0, (255, 255, 255, 0))
            x += unit_len
        x, y = 0, y + unit_len

    padding = 2 * unit_len

    if image is not None:
        width, height = image.size
        size = min(width, height)
        box = ((width - size) / 2, (height - size) / 2, (width + size) / 2, (height + size) / 2)
        image = image.crop(box)
        image = image.resize((
            imagesize[0] - 2 * padding,
            imagesize[1] - 2 * padding
        ), Image.ANTIALIAS).convert('RGBA')

        # Draw background placeholder
        draw = ImageDraw.Draw(qr)
        draw.rectangle([
            int((qr.size[0] - image.size[0] - padding) / 2),
            int((qr.size[1] - image.size[1] - padding) / 2),
            int((qr.size[0] + image.size[0] + padding) / 2),
            int((qr.size[1] + image.size[1] + padding) / 2)
        ], (255, 255, 255, 0))

        # corner = Image.new('RGBA', (16 * 4, 16 * 4), (255, 255, 255, 255))
        # corner_draw = ImageDraw.ImageDraw(corner)
        # corner_draw.pieslice((-64, -64, 64, 64), 0, 340, fill=(255, 255, 255, 0))
        # corner = corner.resize((
        #     int(padding / 2),
        #     int(padding / 2)
        # ), Image.ANTIALIAS)
        # image.paste(corner.copy(), (
        #     image.size[0] - int(padding / 2),
        #     image.size[1] - int(padding / 2)
        # ), corner.copy())

        # image.paste(corner.rotate(90).copy(), (
        #     image.size[0] - int(padding / 2),
        #     -1
        # ), corner.rotate(90).copy())

        # image.paste(corner.rotate(180).copy(), (
        #     0,
        #     0
        # ), corner.rotate(180).copy())
        #
        # image.paste(corner.rotate(-90).copy(), (
        #     -1,
        #     image.size[1] - int(padding / 2)
        # ), corner.rotate(-90).copy())

        mask = Image.open('mask.png')
        mask = mask.resize(image.size, Image.ANTIALIAS).convert('L')

        image.putalpha(mask)

        image = ImageOps.expand(image.crop(image.getbbox()), border=padding, fill=(255, 255, 255, 0))
        qr.paste(image.copy(), (
            int((qr.size[0] - image.size[0]) / 2),
            int((qr.size[1] - image.size[1]) / 2)
        ), image.copy())
    qr = ImageOps.expand(qr.crop(qr.getbbox()), border=unit_len * 2, fill=(255, 255, 255, 0))

    if gold == 'background':
        bg = Image.open('gold-light.jpg')
        bg = bg.resize(qr.size, Image.ANTIALIAS).convert('RGBA')
        qr = Image.composite(qr, bg, qr)

    return qr