|
|
@ -6,7 +6,7 @@ from flask import render_template
|
|
|
|
import glob
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
UPLOAD_FOLDER = ".\static\img\\"
|
|
|
|
UPLOAD_FOLDER = os.path.join("static", "img")
|
|
|
|
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
|
|
|
|
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
|
|
|
|
def allowed_file(filename):
|
|
|
|
def allowed_file(filename):
|
|
|
|
return '.' in filename and \
|
|
|
|
return '.' in filename and \
|
|
|
@ -36,11 +36,23 @@ from flask import request
|
|
|
|
def upload_file():
|
|
|
|
def upload_file():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
file = request.files['tile']
|
|
|
|
file = request.files['tile']
|
|
|
|
overwrite = request.form["overwrite"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if file and allowed_file(file.filename):
|
|
|
|
if file and allowed_file(file.filename):
|
|
|
|
filename, fileextension = os.path.splitext(file.filename)
|
|
|
|
filename, fileextension = os.path.splitext(file.filename)
|
|
|
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], (overwrite + fileextension) ))
|
|
|
|
overwrite = request.form["overwrite"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_file_path = os.path.join(app.config['UPLOAD_FOLDER'], (filename, fileextension))
|
|
|
|
|
|
|
|
overwritten_file_path = os.path.join(app.config['UPLOAD_FOLDER'], (overwrite, '.png'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(overwritten_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
# print("==============================================================")
|
|
|
|
# print("==============================================================")
|
|
|
|
# print(fileextension)
|
|
|
|
# print(fileextension)
|
|
|
|