def test_save_load(self): width, height = self.pnggrid.image.size string_io = StringIO() self.pnggrid.image.save(string_io, 'PNG') image = PIL.Image.open(StringIO(string_io.getvalue())) pnggrid = PNGGrid(image) self.assertEqual(pnggrid.image.size, (width, height)) for y in xrange(0, height): for x in xrange(0, width): self.assertEqual(pnggrid[x, y], self.pnggrid[x, y]) self.assertEqual(self.pnggrid.get_data(), pnggrid.get_data())
#!/usr/bin/env python import os.path import sys from pnggrid import PNGGrid if __name__ == '__main__': for arg in sys.argv[1:]: with open(arg) as utfgrid_file: pnggrid = PNGGrid.from_utfgrid_file(utfgrid_file) with open(os.path.splitext(arg)[0] + '.png', 'w') as pnggrid_file: pnggrid.image.save(pnggrid_file)
def setUp(self): self.pnggrid = PNGGrid.from_utfgrid_file(open('demo.json'))
def setUp(self): self.utfgrid = UTFGrid.from_file(open('europe.json')) self.pnggrid = PNGGrid.from_utfgrid_file(open('europe.json'))