upload image and replace

master
Boyana 1 year ago
parent 49fc56f028
commit 4494306bb3

@ -1,11 +1,19 @@
# This is a flask application that overlaps uploaded images and text on top of images laid out in a grid on the browser.
from flask import Flask
from flask import request
from flask import request, redirect
from flask import render_template
import glob
import os
UPLOAD_FOLDER = './static/img/'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/")
def overlap():
@ -13,3 +21,23 @@ def overlap():
print(images)
return render_template("mosaic.html", images=images)
from flask import request
@app.route('/upload', methods=['POST'])
def upload_file():
if request.method == 'POST':
file = request.files['tile']
# print(request.files["zine test.png"])
if file and allowed_file(file.filename):
filename = file.filename
print("zine test.png",filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
overwrite = request.form["overwrite"]
os.system(f"cp ./static/img/{ filename } ./static/img/{ overwrite }")
os.system(f"rm ./static/img/{ filename }")
return redirect("/")
# f = request.files['the_file']
# f.save('/var/www/uploads/uploaded_file.txt')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 484 KiB

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 KiB

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 KiB

After

Width:  |  Height:  |  Size: 490 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 469 KiB

After

Width:  |  Height:  |  Size: 469 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 667 KiB

After

Width:  |  Height:  |  Size: 668 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 KiB

After

Width:  |  Height:  |  Size: 498 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 KiB

After

Width:  |  Height:  |  Size: 428 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 567 KiB

After

Width:  |  Height:  |  Size: 567 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 687 KiB

After

Width:  |  Height:  |  Size: 688 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 492 KiB

After

Width:  |  Height:  |  Size: 492 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 KiB

After

Width:  |  Height:  |  Size: 373 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 KiB

After

Width:  |  Height:  |  Size: 426 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 KiB

After

Width:  |  Height:  |  Size: 721 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 430 KiB

After

Width:  |  Height:  |  Size: 430 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 KiB

After

Width:  |  Height:  |  Size: 402 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 341 KiB

After

Width:  |  Height:  |  Size: 342 KiB

@ -6,7 +6,7 @@
margin: 0;
}
img{
width: 20vw;
width: 25vw;
margin: 0;
padding: 0;
}
@ -17,5 +17,13 @@
</head>
<body>
{% for image in images %}<img src="{{image}}">{% endfor %}
<form action="/upload" method="POST" enctype="multipart/form-data">
<label for="tile">Choose a profile picture:</label>
<input type="file"
id="tile" name="tile" required>
<input type="text" name="overwrite" required>
<input type="submit" value="Upload">
</form>
</body>
</html>
Loading…
Cancel
Save