Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 587224c

Browse files
committed
Launch
Pending Heroku link
1 parent 2a1289c commit 587224c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+529
-2
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/iBulk.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: python app.py
2+
web: gunicorn app:app

README.md

Lines changed: 94 additions & 2 deletions

app.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from flask import Flask, render_template, request, send_from_directory
2+
from PIL import Image
3+
from werkzeug.utils import secure_filename
4+
import os
5+
import zipfile
6+
from datetime import datetime
7+
8+
app = Flask(__name__)
9+
app.config['UPLOAD_FOLDER'] = 'uploads'
10+
app.config['OUTPUT_FOLDER'] = 'output'
11+
app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'gif'}
12+
13+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
14+
os.makedirs(app.config['OUTPUT_FOLDER'], exist_ok=True)
15+
16+
def allowed_file(filename):
17+
return '.' in filename and \
18+
filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']
19+
20+
@app.route('/', methods=['GET', 'POST'])
21+
def index():
22+
if request.method == 'POST':
23+
files = request.files.getlist('file')
24+
output_format = request.form.get('output_format')
25+
width = request.form.get('width')
26+
height = request.form.get('height')
27+
28+
# If width or height is not provided, use None to keep original size
29+
width = int(width) if width else None
30+
height = int(height) if height else None
31+
32+
file_paths = []
33+
for file in files:
34+
if file and allowed_file(file.filename):
35+
filename = secure_filename(file.filename)
36+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
37+
file.save(file_path)
38+
img = Image.open(file_path)
39+
img = img.convert('RGB')
40+
41+
# If width and height are provided, resize the image
42+
if width and height:
43+
img.thumbnail((width, height))
44+
45+
base_filename, _ = os.path.splitext(filename)
46+
output_filename = base_filename + '.' + output_format
47+
output_filepath = os.path.join(app.config['OUTPUT_FOLDER'], output_filename)
48+
img.save(output_filepath)
49+
file_paths.append(output_filepath)
50+
51+
# Create a zip file containing all the output files
52+
zip_filename = datetime.now().strftime('%Y%m%d%H%M%S') + '.zip'
53+
zip_path = os.path.join(app.config['OUTPUT_FOLDER'], zip_filename)
54+
with zipfile.ZipFile(zip_path, 'w') as zipf:
55+
for file_path in file_paths:
56+
zipf.write(file_path, arcname=os.path.basename(file_path))
57+
58+
return send_from_directory(app.config['OUTPUT_FOLDER'], zip_filename, as_attachment=True)
59+
60+
return render_template('index.html')
61+
62+
if __name__ == '__main__':
63+
app.run(port=5000, debug=True)

0 commit comments

Comments
 (0)