2023-09-24 13:56:01 +00:00
|
|
|
import io
|
2023-08-31 18:15:50 +00:00
|
|
|
from services.image import ImageService
|
|
|
|
from flask import request, Response, Blueprint, jsonify, send_file
|
|
|
|
|
|
|
|
image_blueprint = Blueprint('image_blueprint', __name__)
|
|
|
|
image_service = ImageService()
|
|
|
|
|
|
|
|
@image_blueprint.route('/image/blur', methods=['POST'])
|
|
|
|
def blur_image():
|
2023-09-21 20:57:47 +00:00
|
|
|
radius = int(request.args.get('radius'))
|
|
|
|
image = request.get_data()
|
2023-08-31 18:15:50 +00:00
|
|
|
|
|
|
|
if radius and image:
|
2023-10-03 18:31:33 +00:00
|
|
|
return send_file(io.BytesIO(image_service.box_blur_image(image, radius)),
|
|
|
|
mimetype='image/png',
|
2023-08-31 18:15:50 +00:00
|
|
|
as_attachment=True,
|
2023-10-03 18:31:33 +00:00
|
|
|
download_name='blurred_image.png')
|
2023-08-31 18:15:50 +00:00
|
|
|
|
2023-09-18 00:55:40 +00:00
|
|
|
return "Bad request", 400
|
2023-08-31 18:15:50 +00:00
|
|
|
|
|
|
|
|
2023-09-18 00:55:40 +00:00
|
|
|
@image_blueprint.route('/image/load-small-image', methods=['GET'])
|
2023-08-31 18:15:50 +00:00
|
|
|
def get_simple_image():
|
2023-09-24 13:56:01 +00:00
|
|
|
return send_file(io.BytesIO(image_service.get_simple_image()),
|
2023-09-18 00:55:40 +00:00
|
|
|
mimetype='image/png',
|
|
|
|
as_attachment=True,
|
|
|
|
download_name='small-image.png')
|
2023-08-31 18:15:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@image_blueprint.route('/image/load-big-image', methods=['GET'])
|
|
|
|
def get_big_image():
|
2023-09-24 13:56:01 +00:00
|
|
|
return send_file(io.BytesIO(image_service.get_big_image()),
|
2023-09-18 00:55:40 +00:00
|
|
|
mimetype='image/png',
|
|
|
|
as_attachment=True,
|
|
|
|
download_name='big-image.png')
|
2023-08-31 18:15:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@image_blueprint.route('/image/save-big-image', methods=['POST'])
|
2023-09-18 00:55:40 +00:00
|
|
|
def save_image():
|
2023-09-21 20:57:47 +00:00
|
|
|
image_service.save_image(request.get_data())
|
2023-09-24 13:56:01 +00:00
|
|
|
|
|
|
|
return "OK", 200
|