diff --git a/parts/maps/404.png b/parts/maps/404.png new file mode 100644 index 0000000..441676b Binary files /dev/null and b/parts/maps/404.png differ diff --git a/parts/maps/elab.png b/parts/maps/elab.png new file mode 100644 index 0000000..2413b2f Binary files /dev/null and b/parts/maps/elab.png differ diff --git a/parts/maps/here.png b/parts/maps/here.png new file mode 100644 index 0000000..fdc41c3 Binary files /dev/null and b/parts/maps/here.png differ diff --git a/parts/server.py b/parts/server.py index d5d30b3..cd60df4 100644 --- a/parts/server.py +++ b/parts/server.py @@ -6,7 +6,9 @@ from functools import wraps from sqlalchemy.sql import select from sqlalchemy.sql import text from flask import Flask -from flask import render_template, send_from_directory, request, Response +from flask import render_template, send_from_directory, request, Response, send_file +from PIL import Image, ImageDraw +from io import BytesIO from werkzeug.utils import secure_filename import pprint @@ -38,6 +40,12 @@ def requires_auth(f): return f(*args, **kwargs) return decorated +def serveImage(img): + img_io = BytesIO() + img.save(img_io, 'PNG') + img_io.seek(0) + return send_file(img_io, mimetype='image/png') + @app.route('/parts') def index(): return render_template('partsearch.html') @@ -96,6 +104,21 @@ def query(filter_dummy, query): r.close() return json.dumps(l) +@app.route('/parts/map/') +def getMap(mapurl): + try: + mapimage = Image.open('maps/' + mapurl) + except FileNotFoundError: + return serveImage(Image.open("maps/404.png")) + if request.args.get('x') is not None and request.args.get('y') is not None: + x = int(request.args.get('x')) + y = int(request.args.get('y')) + pointer = Image.open('maps/here.png') + width, height = pointer.size + mapimage.paste(pointer, (x - int(width/2), y-int(height/2)), pointer) + return serveImage(mapimage) + + @app.route('/parts/getfile/') def getfile(filename): if(re.match('^[\w\-_]+$', filename) == None):