committing martinos updates
@ -0,0 +1,128 @@
|
|||||||
|
# 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, redirect
|
||||||
|
from flask import render_template
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from shutil import copyfile, move
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
UPLOAD_FOLDER = os.path.join("static", "img")
|
||||||
|
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'mp3', 'm4a', 'ogg', 'ogv', 'mp4', 'mkv'}
|
||||||
|
def allowed_file(filename):
|
||||||
|
return '.' in filename and \
|
||||||
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||||
|
|
||||||
|
def lastupload(imgpath):
|
||||||
|
files = glob.glob('./static/img/' + imgpath[0:2] + '/*')
|
||||||
|
files.sort(reverse=True)
|
||||||
|
return files[0]
|
||||||
|
|
||||||
|
# create flask application
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# configure the upload folder
|
||||||
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||||
|
|
||||||
|
# load the settings of the applicaiton
|
||||||
|
# (to handle the routing correctly)
|
||||||
|
app.config.from_pyfile('settings.py')
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def overlap():
|
||||||
|
lastfiles = []
|
||||||
|
for i in range (0,42):
|
||||||
|
last=lastupload(str(i).zfill(2))
|
||||||
|
lastfiles.append(last)
|
||||||
|
images = glob.glob('./static/img/*.png')
|
||||||
|
images.sort()
|
||||||
|
print(images)
|
||||||
|
print(lastfiles)
|
||||||
|
|
||||||
|
return render_template("mosaic2.html", lastfiles=lastfiles, images=images)
|
||||||
|
|
||||||
|
from flask import request
|
||||||
|
|
||||||
|
@app.route('/upload/', methods=['POST'])
|
||||||
|
def upload_file():
|
||||||
|
if request.method == 'POST':
|
||||||
|
file = request.files['tile']
|
||||||
|
|
||||||
|
if file and allowed_file(file.filename):
|
||||||
|
filename, fileextension = os.path.splitext(file.filename)
|
||||||
|
overwrite = request.form["overwrite"]
|
||||||
|
|
||||||
|
input_file_path = os.path.join(app.config['UPLOAD_FOLDER'], overwrite + '/' + filename + fileextension)
|
||||||
|
overwritten_file_path = os.path.join(app.config['UPLOAD_FOLDER'], overwrite + fileextension)
|
||||||
|
|
||||||
|
print("[input file path]:", input_file_path)
|
||||||
|
print("[overwritten file path]:", overwritten_file_path)
|
||||||
|
|
||||||
|
# if 'png' not in fileextension:
|
||||||
|
# print("--- convert uploaded image to png")
|
||||||
|
# cmd = f"convert { input_file_path } { overwritten_file_path }"
|
||||||
|
# os.system(cmd)
|
||||||
|
|
||||||
|
file.save(input_file_path)
|
||||||
|
|
||||||
|
file.save(overwritten_file_path)
|
||||||
|
|
||||||
|
# print("==============================================================")
|
||||||
|
# print(fileextension)
|
||||||
|
# print(f"copy { UPLOAD_FOLDER + file.filename} { UPLOAD_FOLDER + overwrite + fileextension }")
|
||||||
|
# os.system(f"copy { UPLOAD_FOLDER + file.filename} { UPLOAD_FOLDER + overwrite + fileextension }")
|
||||||
|
# print(f"del { UPLOAD_FOLDER + file.filename }")
|
||||||
|
# os.system(f"del { UPLOAD_FOLDER + file.filename }")
|
||||||
|
|
||||||
|
return redirect("/")
|
||||||
|
# f = request.files['the_file']
|
||||||
|
# f.save('/var/www/uploads/uploaded_file.txt')
|
||||||
|
|
||||||
|
#to refer backto zoomreplace.html
|
||||||
|
@app.route('/image/static/img/<imgpath>')
|
||||||
|
def zoomedimage(imgpath):
|
||||||
|
print (imgpath)
|
||||||
|
# list the files in imgpath[0:2], pass them to template
|
||||||
|
files = glob.glob('./static/img/' + imgpath[0:2] + '/*')
|
||||||
|
files.sort(reverse=True)
|
||||||
|
print(files)
|
||||||
|
return render_template("zoomreplace2.html", image=imgpath, files=files )
|
||||||
|
|
||||||
|
@app.route('/upload2/<image>', methods=['POST'])
|
||||||
|
def upload2_file(image):
|
||||||
|
if request.method == 'POST':
|
||||||
|
file = request.files['tile']
|
||||||
|
|
||||||
|
if file and allowed_file(file.filename):
|
||||||
|
filename, fileextension = os.path.splitext(file.filename)
|
||||||
|
overwrite = os.path.splitext(image)[0] #00 . png
|
||||||
|
|
||||||
|
input_file_path = os.path.join(app.config['UPLOAD_FOLDER'], overwrite + '/' + filename + fileextension)
|
||||||
|
# overwritten_file_path = os.path.join(app.config['UPLOAD_FOLDER'], overwrite + fileextension)
|
||||||
|
|
||||||
|
print("[input file path]:", input_file_path)
|
||||||
|
# print("[overwritten file path]:", overwritten_file_path)
|
||||||
|
|
||||||
|
# if 'png' not in fileextension:
|
||||||
|
# print("--- convert uploaded image to png")
|
||||||
|
# cmd = f"convert { input_file_path } { overwritten_file_path }"
|
||||||
|
# os.system(cmd)
|
||||||
|
|
||||||
|
# save it in the main folder with the number as the name
|
||||||
|
|
||||||
|
file.save(input_file_path)
|
||||||
|
|
||||||
|
# file.save(overwritten_file_path)
|
||||||
|
|
||||||
|
# and save it in the folder with the date as the name
|
||||||
|
number_folder = image[0:2]
|
||||||
|
datething = str(datetime.now()).replace(":", "").replace(" ", "").replace("-", "").replace(".", "")
|
||||||
|
print(datething)
|
||||||
|
memory_file_path = os.path.join(app.config['UPLOAD_FOLDER'],number_folder, datething + fileextension)
|
||||||
|
|
||||||
|
print(memory_file_path)
|
||||||
|
# tempfile.save(memory_file_path)
|
||||||
|
move(input_file_path, memory_file_path)
|
||||||
|
|
||||||
|
return redirect("/breadcube/overlap/")
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 163 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 173 KiB |
After Width: | Height: | Size: 163 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 327 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 327 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 259 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 259 KiB |
After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 314 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 314 KiB |
After Width: | Height: | Size: 639 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 603 KiB |
After Width: | Height: | Size: 639 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 946 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 946 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 905 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 905 KiB |
After Width: | Height: | Size: 71 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 308 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 308 KiB |
After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 222 KiB |
After Width: | Height: | Size: 96 KiB |
After Width: | Height: | Size: 222 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 366 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 366 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 385 KiB |
After Width: | Height: | Size: 385 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 2.7 MiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 605 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 605 KiB |
After Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 230 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 231 KiB |
After Width: | Height: | Size: 230 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 155 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 194 KiB |
After Width: | Height: | Size: 155 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 439 KiB |
After Width: | Height: | Size: 79 KiB |
After Width: | Height: | Size: 485 KiB |
After Width: | Height: | Size: 439 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 574 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 574 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 93 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 244 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 244 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 366 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 366 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 107 KiB |
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 222 KiB |
Before Width: | Height: | Size: 925 KiB |
Before Width: | Height: | Size: 925 KiB |
Before Width: | Height: | Size: 222 KiB |
After Width: | Height: | Size: 926 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 980 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 980 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 754 KiB |