def preview(): global curNoisePreviewDir set_scene() # query=urllib.unquote(request.query_string).decode('utf8') # # print "request query:", query # print "request query (json):", json.dumps(query) if curNoisePreviewDir == "" or \ not os.path.exists(curNoisePreviewDir): curNoisePreviewDir = tempfile.mkdtemp(prefix='glow-noise-') cmdLineArgs = "glow --input={0} --preview={1} --verbose".format(curSceneFile, curNoisePreviewDir) print "Calling glow:", cmdLineArgs ret = glow.run(cmdLineArgs.split()) retVal = json.dumps({'glow':ret}), 500, {'ContentType':'application/json'} images = [] if ret == 0: print "-" * 80 for bmpFile in os.listdir(curNoisePreviewDir): f, e = os.path.splitext(bmpFile) bmpPath = curNoisePreviewDir + "/" + bmpFile pngPath = curNoisePreviewDir + "/" + f + ".png" print "{0} -> {1}".format(bmpPath, pngPath) Image.open(bmpPath).save(pngPath, "PNG") if False: bmp = Image.open(bmpFile) png = StringIO() bmp.save(png, format="PNG") png_b64 = StringIO() base64.encode(png, png_b64) images.append({ 'name':f, 'image':png_b64.getvalue() }) print " bmp to png", f print "-" * 80 # retVal = json.dumps({'images':images}), 200, {'ContentType':'application/json'} retVal = json.dumps({'glow':0}), 200, {'ContentType':'application/json'} return retVal
def render(): set_scene() # query=urllib.unquote(request.query_string).decode('utf8') # # print "request query:", query # print "request query (json):", json.dumps(query) (handle, outputName) = tempfile.mkstemp(suffix='.png', prefix='glow-') cmdLineArgs = "glow --input={0} --output={1} --verbose".format(curSceneFile, outputName) print "Calling glow:", cmdLineArgs ret = glow.run(cmdLineArgs.split()) retVal = json.dumps({'glow':ret}), 500, {'ContentType':'application/json'} if ret == 0: b64Img = StringIO() with open(outputName) as img: base64.encode(img, b64Img) retVal = json.dumps({'image':b64Img.getvalue()}), 200, {'ContentType':'application/json'} return retVal
def render_tile(hashId, zoom, tileId): print "Request for hash: {2} tile: {1} at zoom {0}".format(zoom, tileId, hashId) # Generate a consistent name based upon the tile request. # Identical future requests result in the same name. # This is the basis for the tile cache. col,row = tileId.split('.')[0].split('_') TILE_SIZE = 64 x0 = (int(col)-1) * TILE_SIZE x1 = x0 + TILE_SIZE # y is inverted (the pano code assumes y is down...) row = 8 - int(row) y0 = (int(row)-1) * TILE_SIZE y1 = y0 + TILE_SIZE outDir = "assets/tiles/" + hashId if not os.path.exists(outDir): os.mkdir(outDir) outputName = "{}_{}-{}_{}-{}.png".format(zoom, x0, x1, y0, y1) outputFilepath = os.path.join(outDir, outputName) sendFile = False if os.path.exists(outputFilepath): print "Sending cached tile:", outputFilepath sendFile = True else: cmdLineArgs = "glow --input={0} --output={1} --imageArea={2},{3},{4},{5} --gamma={6} --verbose". \ format(curSceneFile, outputFilepath, x0, x1, y0, y1, 1.25) print "Calling glow:", cmdLineArgs sendFile = glow.run(cmdLineArgs.split()) == 0 if sendFile: print "sending {} {}".format(outDir, outputName) return send_from_directory(outDir, outputName) abort(500)
#!/usr/bin/env python cmdLine = "glow --input scenes/mud.json --output=mud-py.png --verbose" if __name__ == "__main__": import sys sys.path.append('debug') import glow glow.run(cmdLine.split())
#!/usr/bin/env python cmdLine = "glow --input scenes/mud.json --output=mud-py.png --verbose" if __name__ == "__main__": import sys sys.path.append("debug") import glow glow.run(cmdLine.split())