Handle pillow file errors and move intermediate file storage to ram
This commit is contained in:
parent
ae9ac584f3
commit
cb5efe5821
3 changed files with 40 additions and 20 deletions
28
README.md
Normal file
28
README.md
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
## steps I have taken while installing on pi
|
||||||
|
git clone [this repo] (I actually used scp)
|
||||||
|
sudo apt install python3-flask
|
||||||
|
rm -rf library_bridge.h and library_bridge.h
|
||||||
|
|
||||||
|
add: export GO111MODULE=on, to the first line of the Makefile
|
||||||
|
make
|
||||||
|
|
||||||
|
edit dhcpcd.conf and uncomment and change:
|
||||||
|
static ip_address=10.209.10.2/24
|
||||||
|
static routers=10.209.10.254
|
||||||
|
static domain_name_servers=10.209.10.255
|
||||||
|
|
||||||
|
edit /etc/nginx/sites-available/default and change:
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8080;
|
||||||
|
proxy_redirect http://127.0.0.1:8080 $scheme://$host:8080;
|
||||||
|
}
|
||||||
|
to
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:5000;
|
||||||
|
proxy_redirect http://127.0.0.1:8080 $scheme://$host:5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
systemctl stop & enable labelapi.service
|
||||||
|
cp to /etc/systemd/system label_printer.service, and enable
|
28
app.py
28
app.py
|
@ -10,8 +10,8 @@ from file_handler import *
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
import os
|
import os
|
||||||
|
|
||||||
generated_image_filename = "generated.png"
|
text_image_filename = "text_image.png"
|
||||||
uploaded_image_filename = "uploaded" #extention is depended on uploaded file format
|
uploaded_image_filename = "uploaded_image.png"
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -90,20 +90,21 @@ def image():
|
||||||
return redirect(request.url)
|
return redirect(request.url)
|
||||||
if file:
|
if file:
|
||||||
extension = os.path.splitext(file.filename)[1]
|
extension = os.path.splitext(file.filename)[1]
|
||||||
session["uploaded image path"] = uploaded_image_filename+extension
|
|
||||||
|
|
||||||
filepath = get_file_path(session, session["uploaded image path"])
|
try:
|
||||||
file.save(filepath)
|
message, status, img = process_image(file.stream)
|
||||||
|
session["uploaded image path"] = uploaded_image_filename
|
||||||
|
img.save(get_file_path(session, session["uploaded image path"]))
|
||||||
|
except Exception as e:
|
||||||
|
message = f"{e}"
|
||||||
|
status = "Error"
|
||||||
|
|
||||||
message, status, img = process_image(filepath)
|
|
||||||
img.save(filepath)
|
|
||||||
|
|
||||||
if status == "Error":
|
if status == "Error":
|
||||||
session["uploaded image path"] = None
|
session["uploaded image path"] = None
|
||||||
return render_image_template("Error: " + message, "red")
|
return render_image_template("Error: " + message, "red")
|
||||||
|
|
||||||
elif status == "Info":
|
elif status == "Info":
|
||||||
session["text image path"] = None
|
|
||||||
return render_image_template("Info: " + message, "black")
|
return render_image_template("Info: " + message, "black")
|
||||||
|
|
||||||
return render_image_template()
|
return render_image_template()
|
||||||
|
@ -173,7 +174,7 @@ def text_form():
|
||||||
|
|
||||||
get_folder_path(session)
|
get_folder_path(session)
|
||||||
|
|
||||||
session["text image path"] = generated_image_filename
|
session["text image path"] = text_image_filename
|
||||||
img.save(get_file_path(session, session["text image path"]))
|
img.save(get_file_path(session, session["text image path"]))
|
||||||
print()
|
print()
|
||||||
print(session["text image path"])
|
print(session["text image path"])
|
||||||
|
@ -216,15 +217,6 @@ def user_data(filename):
|
||||||
return send_from_directory(get_folder_path(session), filename)
|
return send_from_directory(get_folder_path(session), filename)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/uploads/<filename>')
|
|
||||||
def uploaded_file(filename):
|
|
||||||
return redirect(url_for('static', filename='uploads/' + filename))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/text/<filename>')
|
|
||||||
def generated_file(filename):
|
|
||||||
return redirect(url_for('static', filename='text/' + filename))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
@ -11,8 +11,8 @@ def format_image_to_label(path):
|
||||||
|
|
||||||
return new_image
|
return new_image
|
||||||
|
|
||||||
def process_image(path):
|
def process_image(image_filestream):
|
||||||
image = Image.open(path)
|
image = Image.open(image_filestream)
|
||||||
message = None
|
message = None
|
||||||
status = None
|
status = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue