Exemple #1
0
def _get_png_info(**kw):
    """\
    Returns the width, height and the pixels of the provided PNG file.
    """
    reader = PNGReader(**kw)
    w, h, pixels, meta = reader.asDirect()
    return w, h, _make_pixel_array(pixels, meta['greyscale'])
Exemple #2
0
def test_greyscale():
    qr = segno.make_qr('test')
    buff = io.BytesIO()
    qr.save(buff, kind='png', quiet_zone='white')
    buff.seek(0)
    reader = PNGReader(file=buff)
    reader.preamble()
    assert reader.greyscale
Exemple #3
0
def test_greyscale():
    fn = _make_tmp_png_filename()
    res = cli.main(['--quiet-zone=white', '--output={0}'.format(fn), 'test'])
    with open(fn, 'rb') as f:
        data = io.BytesIO(f.read())
    os.unlink(fn)
    assert 0 == res
    reader = PNGReader(file=data)
    reader.preamble()
    assert reader.greyscale
Exemple #4
0
def test_plte_no_transparency():
    qr = segno.make_qr('test')
    buff = io.BytesIO()
    dark = (0, 0, 139)
    light = (255, 255, 255)
    qr.save(buff, kind='png', dark=dark, light=light)
    buff.seek(0)
    reader = PNGReader(file=buff)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 2 == len(palette)
    assert dark in palette
    assert light in palette
Exemple #5
0
def test_plte():
    qr = segno.make_qr('test')
    buff = io.BytesIO()
    dark = (0, 0, 139)
    qr.save(buff, kind='png', dark=dark, light=None)
    buff.seek(0)
    reader = PNGReader(file=buff)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 2 == len(palette)
    assert 0 == palette[0][3]  # Transparent color
    dark_with_alpha = dark + (255, )
    assert dark_with_alpha in palette
Exemple #6
0
def test_not_greyscale():
    qr = segno.make_qr('test')
    buff = io.BytesIO()
    qr.save(buff, kind='png',
            quiet_zone=None)  # Three "colors": white, black, transparent
    buff.seek(0)
    reader = PNGReader(file=buff)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 3 == len(palette)
    assert 0 == palette[0][3]  # Transparent color
    assert (0, 0, 0, 255) in palette  # black
    assert (255, 255, 255, 255) in palette  # white
Exemple #7
0
def test_not_greyscale():
    fn = _make_tmp_png_filename()
    res = cli.main(
        ['--quiet-zone=transparent', '--output={0}'.format(fn), 'test'])
    with open(fn, 'rb') as f:
        data = io.BytesIO(f.read())
    os.unlink(fn)
    assert 0 == res
    reader = PNGReader(file=data)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 3 == len(palette)
    assert 0 == palette[0][3]  # Transparent color
    assert (0, 0, 0, 255) in palette  # black
    assert (255, 255, 255, 255) in palette  # white
Exemple #8
0
def test_plte_colors():
    fn = _make_tmp_png_filename()
    res = cli.main([
        '--quiet-zone=green', '--finder-dark=purple', '--finder-light=yellow',
        '--output={0}'.format(fn), 'test'
    ])
    with open(fn, 'rb') as f:
        data = io.BytesIO(f.read())
    os.unlink(fn)
    assert 0 == res
    reader = PNGReader(file=data)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 5 == len(palette)
    assert (0, 0, 0) in palette
    assert (255, 255, 255) in palette
    assert colors._color_to_rgb('green') in palette
    assert colors._color_to_rgb('purple') in palette
    assert colors._color_to_rgb('yellow') in palette
def test_issue_54_notinverted(dark, light, transparent):
    qr = segno.make('The Beatles')
    assert 'M4-M' == qr.designator
    out = io.BytesIO()
    scale = 5
    qr.save(out, kind='png', scale=scale, dark=dark, light=light)
    out.seek(0)
    reader = PNGReader(file=out)
    w, h, pixels, meta = reader.read()
    width, height = qr.symbol_size(scale=scale)
    assert width == w
    assert height == h
    assert meta['greyscale']
    border_row = tuple([1] * w)
    expected_row = tuple([1] * 2 * scale + [0] * 7 * scale + [1])
    for idx, row in enumerate(pixels):
        if idx < 10:
            assert border_row == tuple(row)
        elif idx == 10:
            assert expected_row == tuple(row)[:len(expected_row)]
            break
    assert transparent == reader.transparent
Exemple #10
0
def test_plte_colors():
    qr = segno.make_qr('test')
    buff = io.BytesIO()
    dark = (0, 0, 139)
    light = (255, 255, 255)
    qr.save(buff,
            kind='png',
            dark=dark,
            light=light,
            quiet_zone='green',
            finder_dark='purple',
            finder_light='yellow')
    buff.seek(0)
    reader = PNGReader(file=buff)
    reader.preamble()
    assert not reader.greyscale
    palette = reader.palette()
    assert 5 == len(palette)
    assert dark in palette
    assert light in palette
    assert colors._color_to_rgb('green') in palette
    assert colors._color_to_rgb('purple') in palette
    assert colors._color_to_rgb('yellow') in palette