mirror of https://github.com/ivanch/tcc.git
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import io
|
|
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():
|
|
radius = int(request.args.get('radius'))
|
|
image = request.get_data()
|
|
|
|
if radius and image:
|
|
return send_file(io.BytesIO(image_service.box_blur_image(image, radius)),
|
|
mimetype='image/png',
|
|
as_attachment=True,
|
|
download_name='blurred_image.png')
|
|
|
|
return "Bad request", 400
|
|
|
|
|
|
@image_blueprint.route('/image/load-small-image', methods=['GET'])
|
|
def get_simple_image():
|
|
return send_file(io.BytesIO(image_service.get_simple_image()),
|
|
mimetype='image/png',
|
|
as_attachment=True,
|
|
download_name='small-image.png')
|
|
|
|
|
|
@image_blueprint.route('/image/load-big-image', methods=['GET'])
|
|
def get_big_image():
|
|
return send_file(io.BytesIO(image_service.get_big_image()),
|
|
mimetype='image/png',
|
|
as_attachment=True,
|
|
download_name='big-image.png')
|
|
|
|
|
|
@image_blueprint.route('/image/save-big-image', methods=['POST'])
|
|
def save_image():
|
|
image_service.save_image(request.get_data())
|
|
|
|
return "OK", 200
|