consertos flask

This commit is contained in:
José Henrique 2023-09-21 17:57:47 -03:00
parent 1f63985364
commit 125b456743
4 changed files with 11 additions and 64 deletions

View File

@ -6,8 +6,6 @@ ENV PYTHONUNBUFFERED=1
WORKDIR /app WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget && ls RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget && ls
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
@ -19,6 +17,8 @@ RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
mv big-image.png ./static && \ mv big-image.png ./static && \
mv video.mp4 ./static mv video.mp4 ./static
COPY . .
RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \ --mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt python -m pip install -r requirements.txt

View File

@ -1,49 +0,0 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/compose/compose-file/
# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
server:
build:
context: .
ports:
- 5000:5000
# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker compose up`.
# depends_on:
# db:
# condition: service_healthy
# db:
# image: postgres
# restart: always
# user: postgres
# secrets:
# - db-password
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=example
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
# expose:
# - 5432
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt

View File

@ -8,8 +8,8 @@ image_service = ImageService()
@image_blueprint.route('/image/blur', methods=['POST']) @image_blueprint.route('/image/blur', methods=['POST'])
def blur_image(): def blur_image():
radius = int(request.form.get('radius')) radius = int(request.args.get('radius'))
image = request.files.get('file') image = request.get_data()
if radius and image: if radius and image:
return send_file(image_service.box_blur_image(image, radius), return send_file(image_service.box_blur_image(image, radius),
@ -38,4 +38,4 @@ def get_big_image():
@image_blueprint.route('/image/save-big-image', methods=['POST']) @image_blueprint.route('/image/save-big-image', methods=['POST'])
def save_image(): def save_image():
image_service.save_image(request.files.get('file')) image_service.save_image(request.get_data())

View File

@ -28,20 +28,15 @@ def box_blur_image_separable(image, blurred_image, radius_x, radius_y):
return blurred_image return blurred_image
def save_image(file_stream):
with open("image.png", "wb") as file:
file.write(file_stream.read())
file.close()
class ImageService: class ImageService:
def __init__(self): def __init__(self):
pass pass
def box_blur_image(self, img, radius): def box_blur_image(self, img, radius):
with Image(filename=img) as image: with Image(blob=img) as image:
image = image.blur(radius, 0) blurred_image = image.clone()
image = image.blur(0, radius) image = box_blur_image_separable(image, blurred_image, radius, 0)
image = box_blur_image_separable(image, blurred_image, 0, radius)
return image return image
def get_simple_image(self): def get_simple_image(self):
@ -53,4 +48,5 @@ class ImageService:
return file.read() return file.read()
def save_image(self, img): def save_image(self, img):
save_image(img) with open("image.png", "wb") as file:
file.write(img)