def test_reading_palettes(): act = open('../data/palettes/palette64.act','rb') palette = mapnik.Palette(act.read(),'act') eq_(palette.to_string(),expected_64); act = open('../data/palettes/palette256.act','rb') palette = mapnik.Palette(act.read(),'act') eq_(palette.to_string(),expected_256); palette = mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb') eq_(palette.to_string(),expected_rgb);
def test_reading_palettes(): with open('../data/palettes/palette64.act', 'rb') as act: palette = mapnik.Palette(act.read(), 'act') eq_(palette.to_string(), expected_64) with open('../data/palettes/palette256.act', 'rb') as act: palette = mapnik.Palette(act.read(), 'act') eq_(palette.to_string(), expected_256) palette = mapnik.Palette(b'\xff\x00\xff\xff\xff\xff', 'rgb') eq_(palette.to_string(), expected_rgb)
def test_render_with_palette(): m = mapnik.Map(600, 400) mapnik.load_map(m, '../data/good_maps/agg_poly_gamma_map.xml') m.zoom_all() im = mapnik.Image(m.width, m.height) mapnik.render(m, im) with open('../data/palettes/palette256.act', 'rb') as act: palette = mapnik.Palette(act.read(), 'act') # test saving directly to filesystem im.save('/tmp/mapnik-palette-test.png', 'png', palette) expected = './images/support/mapnik-palette-test.png' if os.environ.get('UPDATE'): im.save(expected, "png", palette) # test saving to a string with open('/tmp/mapnik-palette-test2.png', 'wb') as f: f.write(im.tostring('png', palette)) # compare the two methods eq_( mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring( 'png32'), mapnik.Image.open('/tmp/mapnik-palette-test2.png').tostring( 'png32'), '%s not eq to %s' % ('/tmp/mapnik-palette-test.png', '/tmp/mapnik-palette-test2.png')) # compare to expected eq_( mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring( 'png32'), mapnik.Image.open(expected).tostring('png32'), '%s not eq to %s' % ('/tmp/mapnik-palette-test.png', expected))
def test_render_with_palette(): m = mapnik.Map(600, 400) mapnik.load_map(m, '../data/good_maps/agg_poly_gamma_map.xml') m.zoom_all() im = mapnik.Image(m.width, m.height) mapnik.render(m, im) act = open('../data/palettes/palette256.act', 'rb') palette = mapnik.Palette(act.read(), 'act') # test saving directly to filesystem im.save('/tmp/mapnik-palette-test.png', 'png', palette) # test saving to a string open('/tmp/mapnik-palette-test2.png', 'wb').write(im.tostring('png', palette)) # compare the two methods eq_( mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(), mapnik.Image.open('/tmp/mapnik-palette-test2.png').tostring()) # compare to expected eq_( mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(), mapnik.Image.open( './images/support/mapnik-palette-test.png').tostring())