forked from emilevs/label_printer
Add image presets functionality
This commit is contained in:
parent
f138db573a
commit
f433ae663f
4 changed files with 57 additions and 5 deletions
19
app.py
19
app.py
|
|
@ -47,6 +47,9 @@ def on_new_user(session):
|
|||
session["fonts"] = fonts()
|
||||
|
||||
|
||||
image_presets = {
|
||||
"Abandoned": "resources/abandoned.jpg"
|
||||
}
|
||||
|
||||
@app.route('/image', methods=['GET', 'POST'])
|
||||
def image():
|
||||
|
|
@ -56,15 +59,27 @@ def image():
|
|||
if 'image' not in request.files:
|
||||
return render_image_template()
|
||||
|
||||
file = request.files['image']
|
||||
|
||||
|
||||
if "dropdown" in request.form and request.form["dropdown"] != "file":
|
||||
path = image_presets[request.form["dropdown"]]
|
||||
class file:
|
||||
filename = os.path.basename(path)
|
||||
stream = open(path, "rb")
|
||||
else:
|
||||
file = request.files['image']
|
||||
|
||||
print(file.stream)
|
||||
|
||||
|
||||
if file.filename == '':
|
||||
return render_image_template()
|
||||
if file:
|
||||
else:
|
||||
extension = os.path.splitext(file.filename)[1]
|
||||
|
||||
try:
|
||||
message, status, img = process_image(file.stream)
|
||||
file.stream.close()
|
||||
session["uploaded image path"] = uploaded_image_filename
|
||||
img.save(get_file_path(session, session["uploaded image path"]))
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
label_width = 213
|
||||
#label_width = 213
|
||||
label_width = 450
|
||||
printer_width = 512
|
||||
|
||||
max_label_length = 2000
|
||||
|
|
|
|||
BIN
resources/abandoned.jpg
Normal file
BIN
resources/abandoned.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
|
|
@ -8,7 +8,19 @@
|
|||
{% block content %}
|
||||
<h1>Upload Image</h1>
|
||||
<form method="POST" action="/image" enctype="multipart/form-data">
|
||||
<input type="file" name="image">
|
||||
{% if label_width == 450 %}
|
||||
<label for="dropdown">Image:</label>
|
||||
<select name="dropdown" id="image_preset_dropdown" onchange="handle_dropdown(this.value)">
|
||||
<option value="file">Upload file</option>
|
||||
{% if label_width == 450 %}
|
||||
<option value="Abandoned">Abandoned item</option>
|
||||
{% endif %}
|
||||
</select><br>
|
||||
{%endif%}
|
||||
|
||||
<div id="file">
|
||||
<input type="file" name="image"><br>
|
||||
</div>
|
||||
<input type="submit" value="Generate preview"><br>
|
||||
Recommended image height = {{label_width}}, other sizes will be scaled
|
||||
</form>
|
||||
|
|
@ -18,7 +30,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% if filename %}
|
||||
<img src="user_data/{{filename}}" alt="Uploaded image" style="height: 150px; width: auto;">
|
||||
<img src="user_data/{{filename}}" alt="Uploaded image" style="height: {{label_width * 0.7 }}px; width: auto;">
|
||||
|
||||
<form method="POST" action="/image-print">
|
||||
{% if cut %}
|
||||
|
|
@ -30,5 +42,29 @@
|
|||
|
||||
<input type="submit" value="Print" style="font-size: 2em; padding: 20px 40px;">
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
function get_persistent(name, initial_value) {
|
||||
if (localStorage.getItem(name) == null) {
|
||||
localStorage.setItem(name, initial_value)
|
||||
}
|
||||
return localStorage.getItem(name)
|
||||
}
|
||||
|
||||
dropdown_value = get_persistent("image_preset_dropdown", "file")
|
||||
document.getElementById("image_preset_dropdown").value = dropdown_value
|
||||
handle_dropdown(dropdown_value)
|
||||
|
||||
|
||||
function handle_dropdown(value) {
|
||||
localStorage.setItem("image_preset_dropdown", value)
|
||||
console.log()
|
||||
if (value == "file") {
|
||||
document.getElementById("file").style.display = "inline";
|
||||
} else {
|
||||
document.getElementById("file").style.display = "none";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue