-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (52 loc) · 1.97 KB
/
app.py
File metadata and controls
71 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, request, make_response
import cv2
import numpy as np
# ... rest of your code ...
app = Flask(__name__)
def resize_image(image, width=None, height=None):
# Placeholder for the resize function
return image
def rotate_image(image, angle):
# Placeholder for the rotate function
return image
def apply_filter(image, filter_name):
# Placeholder for the filter function
return image
def add_text(image, text, position=(50, 50), font=cv2.FONT_HERSHEY_SIMPLEX, font_scale=1, color=(255, 255, 255), thickness=2):
text_image = image.copy()
cv2.putText(text_image, text, position, font, font_scale, color, thickness)
return text_image
def convert_to_bw(image):
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/edit', methods=['POST'])
def edit():
file = request.files['image']
mode = request.form['mode']
image = cv2.imdecode(np.frombuffer(file.read(), np.uint8), cv2.IMREAD_COLOR)
# Resize, rotate, and apply filter as required...
# Example: edited_image = resize_image(image, width=500)
# Add text to the image
# Example: edited_image = add_text(edited_image, 'Sample Text')
edited_image = ''
if mode == "b/w":
edited_image = convert_to_bw(image)
elif mode == '90deg':
edited_image = rotate_image(image, 90)
elif mode == '180deg':
edited_image = rotate_image(image, 180)
elif mode == 'resize':
edited_image = resize_image(image, width=500)
else:
edited_image = add_text(image, 'Demo')
# Convert the image to black and white
# Encode the edited image to send it back to the HTML page
retval, buffer = cv2.imencode('.jpg', edited_image)
jpg_as_text = buffer.tobytes()
response = make_response(jpg_as_text)
response.headers.set('Content-Type', 'image/jpeg')
return response
if __name__ == "__main__":
app.run(debug=True)