예제 #1
0
def encode_to_img(string, width=400, border=10):
    qrcode = encode(string)
    matrix = to_matrix(qrcode)
   
    dotsize = (width - (border * 2)) / qrcode['width']
    realwidth = qrcode['width'] * dotsize

    rawdata = ''
    for row in matrix:
        line = ''
        for col in row:
            line += dotsize * chr(col * 255)
        rawdata += dotsize * line

    img = img_fromstring('L', (realwidth, realwidth), rawdata)
    return img_expand(img, border, 255)
예제 #2
0
def encode_to_img(string, width=400, border=10):
    if not string or not string.strip(b'\x00'):
        raise ValueError("You cannot encode a null data in a qrcode.")
    qrcode = encode(string)
    matrix = to_matrix(qrcode)

    dotsize = (width - (border * 2)) / qrcode['width']
    realwidth = qrcode['width'] * dotsize

    rawdata = ''
    for row in matrix:
        line = ''
        for col in row:
            line += dotsize * chr(col * 255)
        rawdata += dotsize * line

    img = img_fromstring('L', (realwidth, realwidth), rawdata)
    return img_expand(img, border, 255)
예제 #3
0
파일: qrimg.py 프로젝트: Natim/qrkit
def encode_to_img(data, width=400, border=10):
    if not isinstance(data, bytes):
        raise ValueError("Please use encode bytes to image.")

    if not data or not data.strip(b'\x00'):
        raise ValueError("You cannot encode a null data in a qrcode.")

    qrcode = encode(data)
    matrix = to_matrix(qrcode)

    dotsize = (width - (border * 2)) // qrcode['width']
    realwidth = qrcode['width'] * dotsize

    rawdata = b''
    for row in matrix:
        line = b''
        for col in row:
            line += dotsize * bytes([col * 255])
        rawdata += dotsize * line

    img = img_frombytes('L', (realwidth, realwidth), rawdata)
    return img_expand(img, border, 255)