maps with container overlays

pull/3/head
Marek Baczynski 6 years ago
parent c4ca575ca1
commit 0fdcd100ff

@ -164,20 +164,28 @@ def query(filter_dummy, query):
r.close() r.close()
return json.dumps(l) return json.dumps(l)
@app.route('/parts/map/<mapurl>') @app.route('/parts/map/<containerID>')
def getMap(mapurl): def getMap(containerID):
s = 'select map, overlay from containers where id = :id;'
r = db_engine.execute(text(s), id=containerID)
l = []
for row in r:
l.append(dict(row))
mapFile = l[0]['map']
overlayFile = l[0]['overlay']
try: try:
mapimage = Image.open('maps/' + mapurl).convert("RGBA") mapImage = Image.open('maps/' + mapFile).convert("RGBA")
overlayImage = Image.open('maps/overlays/' + overlayFile).convert("RGBA")
except FileNotFoundError: except FileNotFoundError:
return serveImage(Image.open("maps/404.png")) return serveImage(Image.open("maps/404.png"))
if request.args.get('x') is not None and request.args.get('y') is not None: # if request.args.get('x') is not None and request.args.get('y') is not None:
x = int(request.args.get('x')) # x = int(request.args.get('x'))
y = int(request.args.get('y')) # y = int(request.args.get('y'))
pointer = Image.open('maps/here.png') # pointer = Image.open('maps/here.png')
pointerLayer = Image.new("RGBA", mapimage.size) # pointerLayer = Image.new("RGBA", mapimage.size)
width, height = pointer.size # width, height = pointer.size
pointerLayer.paste(pointer, (x - int(width/2), y-int(height/2))) # pointerLayer.paste(pointer, (x - int(width/2), y-int(height/2)))
mapimage = Image.alpha_composite(mapimage, pointerLayer) mapimage = Image.alpha_composite(mapImage, overlayImage)
return serveImage(mapimage) return serveImage(mapimage)

Loading…
Cancel
Save