diff --git a/FlaskAPI/.idea/.gitignore b/FlaskAPI/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/FlaskAPI/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/FlaskAPI/.idea/FlaskAPI.iml b/FlaskAPI/.idea/FlaskAPI.iml new file mode 100644 index 0000000..15b7777 --- /dev/null +++ b/FlaskAPI/.idea/FlaskAPI.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/FlaskAPI/.idea/inspectionProfiles/profiles_settings.xml b/FlaskAPI/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/FlaskAPI/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/FlaskAPI/.idea/misc.xml b/FlaskAPI/.idea/misc.xml new file mode 100644 index 0000000..4bdfec8 --- /dev/null +++ b/FlaskAPI/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/FlaskAPI/.idea/modules.xml b/FlaskAPI/.idea/modules.xml new file mode 100644 index 0000000..6fa8fc8 --- /dev/null +++ b/FlaskAPI/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/FlaskAPI/.vscode/launch.json b/FlaskAPI/.vscode/launch.json new file mode 100644 index 0000000..6a28b4c --- /dev/null +++ b/FlaskAPI/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.1", + "configurations": [ + + { + "name": "Python: Flask", + "type": "python", + "request": "launch", + "module": "flask", + "env": { "FLASK_APP": "app.py", "FLASK_DEBUG": "1" }, + "args": ["run", "--no-debugger", "--no-reload"], + "jinja": true, + "justMyCode": true + } + + ] +} diff --git a/FlaskAPI/.vscode/settings.json b/FlaskAPI/.vscode/settings.json new file mode 100644 index 0000000..e69de29 diff --git a/FlaskAPI/__pycache__/app.cpython-310.pyc b/FlaskAPI/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000..c38168b Binary files /dev/null and b/FlaskAPI/__pycache__/app.cpython-310.pyc differ diff --git a/FlaskAPI/app.py b/FlaskAPI/app.py new file mode 100644 index 0000000..b048e75 --- /dev/null +++ b/FlaskAPI/app.py @@ -0,0 +1,12 @@ +from flask import Flask +from controllers.status import status_blueprint +from controllers.image import image_blueprint + +app = Flask(__name__) + +if __name__ == '__main__': + app.run() + +# +app.register_blueprint(status_blueprint) +app.register_blueprint(image_blueprint) \ No newline at end of file diff --git a/FlaskAPI/blurred_temp_image.jpeg b/FlaskAPI/blurred_temp_image.jpeg new file mode 100644 index 0000000..77ff865 Binary files /dev/null and b/FlaskAPI/blurred_temp_image.jpeg differ diff --git a/FlaskAPI/controllers/__pycache__/image.cpython-310.pyc b/FlaskAPI/controllers/__pycache__/image.cpython-310.pyc new file mode 100644 index 0000000..7cc4314 Binary files /dev/null and b/FlaskAPI/controllers/__pycache__/image.cpython-310.pyc differ diff --git a/FlaskAPI/controllers/__pycache__/status.cpython-310.pyc b/FlaskAPI/controllers/__pycache__/status.cpython-310.pyc new file mode 100644 index 0000000..1eb22a4 Binary files /dev/null and b/FlaskAPI/controllers/__pycache__/status.cpython-310.pyc differ diff --git a/FlaskAPI/controllers/image.py b/FlaskAPI/controllers/image.py new file mode 100644 index 0000000..19322be --- /dev/null +++ b/FlaskAPI/controllers/image.py @@ -0,0 +1,37 @@ +import io +from services.image import ImageService +from static.image_helper import ImageHelper +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.form.get('radius')) + image = request.files.get('file') + + if radius and image: + return send_file(image_service.box_blur_image(image, radius), + mimetype='image/jpeg', + as_attachment=True, + download_name='blurred_image.jpeg') + + return jsonify(status=400, message="Bad request") + + +@image_blueprint.route('/image/load-image', methods=['POST']) +def get_simple_image(): + pass + + +@image_blueprint.route('/image/load-big-image', methods=['GET']) +def get_big_image(): + pass + + +@image_blueprint.route('/image/save-big-image', methods=['POST']) +def save_big_image(): + pass + diff --git a/FlaskAPI/controllers/status.py b/FlaskAPI/controllers/status.py new file mode 100644 index 0000000..5d777ad --- /dev/null +++ b/FlaskAPI/controllers/status.py @@ -0,0 +1,19 @@ +from flask import jsonify, Blueprint + +status_blueprint = Blueprint('status_blueprint', __name__) + + +class StatusController: + def __init__(self): + pass + + def return_ok(self): + return jsonify(status=200) + + +status_controller = StatusController() + + +@status_blueprint.route('/status/ok', methods=['GET']) +def return_ok(): + return jsonify(status=200) diff --git a/FlaskAPI/services/__pycache__/image.cpython-310.pyc b/FlaskAPI/services/__pycache__/image.cpython-310.pyc new file mode 100644 index 0000000..1ba3a5e Binary files /dev/null and b/FlaskAPI/services/__pycache__/image.cpython-310.pyc differ diff --git a/FlaskAPI/services/image.py b/FlaskAPI/services/image.py new file mode 100644 index 0000000..35da64c --- /dev/null +++ b/FlaskAPI/services/image.py @@ -0,0 +1,57 @@ +from wand.image import Image + + +def box_blur_image_separable(image, blurred_image, radius_x, radius_y): + pixels = image.get_pixels() + blurred_pixels = blurred_image.get_pixels() + + for pixel in pixels: + x, y = pixel[0], pixel[1] + + r_total, g_total, b_total = 0, 0, 0 + pixel_count = 0 + for offset_y in range(-radius_y, radius_y + 1): + for offset_x in range(-radius_x, radius_x + 1): + new_x = x + offset_x + new_y = y + offset_y + + if 0 <= new_x < image.width and 0 <= new_y < image.height: + pixel_color = pixels[new_y * image.width + new_x] + r_total += pixel_color.red + g_total += pixel_color.green + b_total += pixel_color.blue + pixel_count += 1 + + blurred_pixel = blurred_pixels[y * image.width + x] + blurred_pixel.red = int(r_total / pixel_count) + blurred_pixel.green = int(g_total / pixel_count) + blurred_pixel.blue = int(b_total / pixel_count) + + return blurred_image + + +class ImageService: + def __init__(self): + pass + + def box_blur_image(self, image, radius): + temp_path = 'temp_image.png' + image.save(temp_path) + + with Image(filename=temp_path) as img: + img.blur(radius, 2) # Apply blur directly to the image object + blurred_temp_path = 'blurred_temp_image.png' + img.save(filename=blurred_temp_path) # Save the modified image + return blurred_temp_path + + + def save_image(self, file_stream): + with open("image.png", "wb") as file: + file.write(file_stream.read()) + file.close() + + def get_simple_image(self): + return Image(filename='path_to_simple_image.png') + + def get_big_image(self): + return Image(filename='path_to_big_image.png') diff --git a/FlaskAPI/static/__pycache__/image_helper.cpython-310.pyc b/FlaskAPI/static/__pycache__/image_helper.cpython-310.pyc new file mode 100644 index 0000000..f8b5084 Binary files /dev/null and b/FlaskAPI/static/__pycache__/image_helper.cpython-310.pyc differ diff --git a/FlaskAPI/static/image_helper.py b/FlaskAPI/static/image_helper.py new file mode 100644 index 0000000..d566946 --- /dev/null +++ b/FlaskAPI/static/image_helper.py @@ -0,0 +1,15 @@ +from wand.image import Image + + +class ImageHelper: + SimpleImage = None + BigImage = None + + @staticmethod + def load_images(): + # ImageHelper.SimpleImage = Image(filename="simpleimage.png") + # ImageHelper.BigImage = Image(filename="bigimage.png") + pass + + +ImageHelper.load_images() diff --git a/FlaskAPI/temp_image.jpeg b/FlaskAPI/temp_image.jpeg new file mode 100644 index 0000000..25783da Binary files /dev/null and b/FlaskAPI/temp_image.jpeg differ