def test_roundtrip_pool(pool): "save a pool as JSON and reload it" tf = tempfile.NamedTemporaryFile() pm.export_pool(pool, tf.name) pool2 = pm.import_pool(tf.name) for (k1, v1), (k2, v2) in zip(sorted(pool.items()), sorted(pool2.items())): assert k1 == k2 assert np.all(v1 == v2)
import os import photomosaic.flickr import photomosaic as pm if not os.path.isfile(os.path.expanduser('~/pools/cats/pool.json')): FLICKR_API_KEY = os.environ['FLICKR_API_KEY'] pm.set_options(flickr_api_key=FLICKR_API_KEY) photomosaic.flickr.from_search('cats', '~/pools/cats/') pool = pm.make_pool('~/pools/cats/*.jpg') pm.export_pool( pool, '~/pools/cats/pool.json') # save color analysis for future reuse
import os import photomosaic as pm POOL_DIR = '/tmp/photomosaic-docs-pool/' pm.rainbow_of_squares(POOL_DIR) pool = pm.make_pool(os.path.join(POOL_DIR, '*.png')) pm.export_pool(pool, os.path.join(POOL_DIR, 'pool.json'))
import os import photomosaic.flickr import photomosaic as pm if not os.path.isfile(os.path.expanduser("~/pools/cats/pool.json")): FLICKR_API_KEY = os.environ["FLICKR_API_KEY"] pm.set_options(flickr_api_key=FLICKR_API_KEY) photomosaic.flickr.from_search("cats", "~/pools/cats/") pool = pm.make_pool("~/pools/cats/*.jpg") pm.export_pool(pool, "~/pools/cats/pool.json") # save color analysis for future reuse