Skip to content

Add gitpod config #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM gitpod/workspace-full

USER gitpod

# Install custom tools, runtime, etc. using apt-get
# For example, the command below would install "bastet" - a command line tetris clone:
#
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
#
# More information: https://www.gitpod.io/docs/config-docker/
4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tasks:
- init: pip install -r ./requirements.txt
image:
file: .gitpod.Dockerfile
8 changes: 8 additions & 0 deletions .idea/image-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/gxercavins/image-api)

# Image API
Image Processing API written in Python, using the Pillow library for image manipulation and exposing the functions with the Flask framework. The API has been tested with jpg, png and bmp formats and is able to flip, rotate and crop an image, as well as blending two images, either RGB or gray scale.

Expand Down
13 changes: 6 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask import Flask, request, render_template, send_from_directory
import os
from PIL import Image
import plat

app = Flask(__name__)

Expand Down Expand Up @@ -49,15 +50,15 @@ def upload():
@app.route("/rotate", methods=["POST"])
def rotate():
# retrieve parameters from html form
angle = request.form['angle']
#angle = request.form['angle']
filename = request.form['image']

# open and process image
target = os.path.join(APP_ROOT, 'static/images')
destination = "/".join([target, filename])

img = Image.open(destination)
img = img.rotate(-1*int(angle))
img = img.resize(plat.now)

# save and return image
destination = "/".join([target, 'temp.png'])
Expand All @@ -71,7 +72,6 @@ def rotate():
# flip filename 'vertical' or 'horizontal'
@app.route("/flip", methods=["POST"])
def flip():

# retrieve parameters from html form
if 'horizontal' in request.form['mode']:
mode = 'horizontal'
Expand Down Expand Up @@ -138,7 +138,7 @@ def crop():
# crop image and show
if crop_possible:
img = img.crop((x1, y1, x2, y2))

# save and return image
destination = "/".join([target, 'temp.png'])
if os.path.isfile(destination):
Expand Down Expand Up @@ -178,9 +178,9 @@ def blend():
img2 = img2.convert('L')

# blend and show image
img = Image.blend(img1, img2, float(alpha)/100)
img = Image.blend(img1, img2, float(alpha) / 100)

# save and return image
# save and return image
destination = "/".join([target, 'temp.png'])
if os.path.isfile(destination):
os.remove(destination)
Expand All @@ -197,4 +197,3 @@ def send_image(filename):

if __name__ == "__main__":
app.run()

1 change: 0 additions & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
def main():
return redirect("https://github.com/gxercavins/image-api/blob/master/README.md", code=302)


# rotate filename the specified degrees
@app.route("/rotate/<angle>/<filename>", methods=["GET"])
def rotate(angle, filename):
Expand Down
2 changes: 2 additions & 0 deletions plat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sky = (1000, 1500)
now = (220, 340)
14 changes: 7 additions & 7 deletions templates/processing.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ <h4>Crop</h4>

<div class="col-lg-6">
<h4>Rotate</h4>
<form id="form-rotate" action="{{ url_for('rotate') }}" method="POST" enctype="multipart/form-data">
<input type="number" name="angle" min="-359" max="359" placeholder="degrees" required>
<button id="btnRotate" class="btn btn-lg btn-success" type="submit">Go</button>
<form id="form-rotate" action="{{ url_for('rotate') }}" method="POST" enctype="multipart/form-data">
<!-- <input type="number" name="angle" min="-359" max="359" placeholder="degrees" required>-->
<button id="btnRotate" class="btn btn-lg btn-success" type="submit">Gerar NOW</button>
<input type="text" class="hidden" name="image" value="{{ image_name }}">
</form>

<h4>Blend</h4>
<form id="form-blend"" action="{{ url_for('blend') }}" method="POST" enctype="multipart/form-data">
<input type="number" name="alpha" placeholder="alpha(%)" min="0" max="100" required>
<form id="form-blend"" action="{{ url_for('blend') }}" method="POST" enctype="multipart/form-data">
<input type="number" name="alpha" placeholder="alpha(%)" min="0" max="100" required>
<button id="btnBlend" class="btn btn-lg btn-success" type="submit">Go</button>
<input type="text" class="hidden" name="image" value="{{ image_name }}">
</form>

</div>
</div>

Expand Down