-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (21 loc) · 781 Bytes
/
app.py
File metadata and controls
30 lines (21 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, request, send_file
from pystrich.datamatrix import DataMatrixEncoder
from PIL import Image
import io
app = Flask(__name__)
@app.route('/generate', methods=['GET'])
def generate_datamatrix():
data = request.args.get('data')
if not data:
return {"error": "Missing 'data' parameter"}, 400
encoder = DataMatrixEncoder(data)
img_data = encoder.get_imagedata() # Holt das Bild als Rohbytes
# Konvertiere das Byte-Array in ein PIL-Image
img = Image.open(io.BytesIO(img_data))
# Speichere das Bild in einem BytesIO-Objekt
img_io = io.BytesIO()
img.save(img_io, format='PNG')
img_io.seek(0)
return send_file(img_io, mimetype='image/png')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)