Make the back end accept n text fields

This commit is contained in:
TT-392 2025-10-31 15:31:00 +00:00
parent eb1056144c
commit e41695e256
2 changed files with 40 additions and 42 deletions

80
app.py
View file

@ -180,56 +180,54 @@ def text_form():
check_for_new_user(session)
if request.method == 'POST':
print(request.form)
#session["text1"] = {
# "string": request.form["string1"],
# "size": int(request.form["size1"]),
# "pos": int(request.form["pos1"]),
# "bold": "bold1" in request.form,
#}
#session["text2"] = {
# "string": request.form["string2"],
# "size": int(request.form["size2"]),
# "pos": int(request.form["pos2"]),
# "bold": "bold2" in request.form,
#}
line_count = int(request.form["lineCount"])
lines = []
for i in range(0, line_count):
lines.append({
"string": request.form["text" + str(i)],
"size": int(request.form["size" + str(i)]),
"pos": int(request.form["y_pos" + str(i)]),
"bold": False
})
# Clear previously saved font
for font in session["fonts"]:
session["fonts"][font]["selected"] = False
## Clear previously saved font
#for font in session["fonts"]:
# session["fonts"][font]["selected"] = False
# If an invalid font has been submitted, just default to the first one
chosen_font = request.form["font"]
if chosen_font in session["fonts"]:
session["fonts"][chosen_font]["selected"] = True
else:
first_font = next(iter(session["fonts"]))
session["fonts"][first_font]["selected"] = True
## If an invalid font has been submitted, just default to the first one
#chosen_font = request.form["font"]
#if chosen_font in session["fonts"]:
# session["fonts"][chosen_font]["selected"] = True
#else:
# first_font = next(iter(session["fonts"]))
# session["fonts"][first_font]["selected"] = True
# Select the first font that has been marked as selected
chosen_font = None
for font in session["fonts"]:
f = session["fonts"][font]
if f["selected"]:
chosen_font = f
## Select the first font that has been marked as selected
#chosen_font = None
#for font in session["fonts"]:
# f = session["fonts"][font]
# if f["selected"]:
# chosen_font = f
# If the font is still None, something has gone wrong
if chosen_font is None:
return
## If the font is still None, something has gone wrong
#if chosen_font is None:
# return
print(chosen_font)
#message, status, img = gen_image(label_width, session["text1"], session["text2"], chosen_font)
message, status, img = gen_image(label_width, lines, chosen_font)
#if status == "Error":
# session["text image path"] = None
# return render_text_template(message, "red")
if status == "Error":
session["text image path"] = None
return render_text_template(message, "red")
#get_folder_path(session)
get_folder_path(session)
#session["text image path"] = text_image_filename
#img.save(get_file_path(session, session["text image path"]))
session["text image path"] = text_image_filename
img.save(get_file_path(session, session["text image path"]))
#print()
#print(session["text image path"])
print()
print(session["text image path"])
return render_text_template(scrollDown = True)

View file

@ -67,5 +67,5 @@ Text3 = {
"bold": False,
}
gen_image(200, [Text1, Text2, Text3], fonts()["CYBER"])[2].save("aaa.png")
#gen_image(200, [Text1, Text2, Text3], fonts()["CYBER"])[2].save("aaa.png")