Commit aba3eb35 authored by Joel Collins's avatar Joel Collins
Browse files

Return LST as a file

parent 4d40e81f
Loading
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
import logging
from io import BytesIO

import datetime
import numpy as np
from flask import Response
from flask import send_file
from labthings import find_component
from labthings.views import PropertyView
from PIL import Image
@@ -43,5 +43,8 @@ class LSTImageProperty(PropertyView):
            # Create a PNG
            img_bytes = BytesIO()
            Image.fromarray(np.uint8(all_channels), "L").save(img_bytes, "PNG")
            img_bytes.seek(0)
            # Return the image
            return Response(img_bytes.getvalue(), mimetype="image/png")
            #return Response(img_bytes.getvalue(), mimetype="image/png")
            fname = f"lst-{datetime.date.today().isoformat()}.png"
            return send_file(img_bytes, as_attachment=True, attachment_filename=fname)