Implement a checkbox to choose if the text will be bold or not

This commit is contained in:
TT-392 2025-10-09 14:02:05 +00:00 committed by TT-392
parent 3d572fd060
commit 9de5ba5524
4 changed files with 35 additions and 16 deletions

22
app.py
View file

@ -24,12 +24,14 @@ templates = {
"text1": { "text1": {
"string": "Do Not Hack", "string": "Do Not Hack",
"size": 130, "size": 130,
"pos": 0 "pos": 0,
"bold": True
}, },
"text2": { "text2": {
"string": "bottom text", "string": "bottom text",
"size": 50, "size": 50,
"pos": 130 "pos": 130,
"bold": False
}, },
"cut": True "cut": True
}, },
@ -37,12 +39,14 @@ templates = {
"text1": { "text1": {
"string": "Nickname", "string": "Nickname",
"size": 130, "size": 130,
"pos": 0 "pos": 0,
"bold": True
}, },
"text2": { "text2": {
"string": "", "string": "",
"size": 50, "size": 50,
"pos": 130 "pos": 130,
"bold": False
}, },
"cut": True "cut": True
}, },
@ -50,12 +54,14 @@ templates = {
"text1": { "text1": {
"string": "Remove by", "string": "Remove by",
"size": 130, "size": 130,
"pos": 0 "pos": 0,
"bold": True
}, },
"text2": { "text2": {
"string": "", "string": "",
"size": 50, "size": 50,
"pos": 130 "pos": 130,
"bold": False
}, },
"cut": True "cut": True
} }
@ -178,11 +184,13 @@ def text_form():
"string": request.form["string1"], "string": request.form["string1"],
"size": int(request.form["size1"]), "size": int(request.form["size1"]),
"pos": int(request.form["pos1"]), "pos": int(request.form["pos1"]),
"bold": "bold1" in request.form,
} }
session["text2"] = { session["text2"] = {
"string": request.form["string2"], "string": request.form["string2"],
"size": int(request.form["size2"]), "size": int(request.form["size2"]),
"pos": int(request.form["pos2"]), "pos": int(request.form["pos2"]),
"bold": "bold2" in request.form,
} }
# Clear previously saved font # Clear previously saved font
@ -262,5 +270,5 @@ def user_data(filename):
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=False) app.run(debug=True)

View file

@ -1,8 +1,9 @@
class Font: class Font:
def __init__(self, name: str, path: str, stroke_width: int, default: bool = False) -> None: def __init__(self, name: str, path: str, stroke_width: int, stroke_width_bold: int, default: bool = False) -> None:
self.name = name self.name = name
self.path = path self.path = path
self.stroke_width = stroke_width self.stroke_width = stroke_width
self.stroke_width_bold = stroke_width_bold
self.selected = default self.selected = default
def to_dict(self): def to_dict(self):
@ -10,12 +11,13 @@ class Font:
"name": self.name, "name": self.name,
"path": self.path, "path": self.path,
"selected": self.selected, "selected": self.selected,
"stroke_width": self.stroke_width "stroke_width": self.stroke_width,
"stroke_width_bold": self.stroke_width_bold
} }
def fonts(): def fonts():
return { return {
"CYBER": Font("CYBER", "resources/OCRAEXT.TTF", 3, True).to_dict(), "CYBER": Font("CYBER", "resources/OCRAEXT.TTF", 0, 3, True).to_dict(),
"ComicMono": Font("Comic Sans Mono", "resources/ComicMono.ttf", 0).to_dict(), "ComicMono": Font("Comic Sans Mono", "resources/ComicMono.ttf", 0, 2).to_dict(),
"EstupidoEspezial": Font("¡¡¡Estupido-Espezial!!!", "resources/Estupido Espezial.ttf", 1).to_dict() "EstupidoEspezial": Font("¡¡¡Estupido-Espezial!!!", "resources/Estupido Espezial.ttf", 0, 2).to_dict()
} }

View file

@ -32,9 +32,8 @@ def gen_image(height, text1, text2, font):
img = Image.new('1', (width, height), color=1) img = Image.new('1', (width, height), color=1)
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
draw.text((0, text1["pos"]), text1["string"], font=font1, stroke_width = font["stroke_width_bold"] if text1["bold"] else font["stroke_width"], stroke_fill="black")
draw.text((0, text1["pos"]), text1["string"], font=font1, stroke_width=font["stroke_width"], stroke_fill="black") draw.text((0, text2["pos"]), text2["string"], font=font2, stroke_width = font["stroke_width_bold"] if text2["bold"] else font["stroke_width"], stroke_fill="black")
draw.text((0, text2["pos"]), text2["string"], font=font2)
if (width > max_label_length): if (width > max_label_length):

View file

@ -25,6 +25,11 @@
style="width: 40px"><br> style="width: 40px"><br>
Y position: <input type="number" value="{{text1["pos"]}}" name="pos1" required Y position: <input type="number" value="{{text1["pos"]}}" name="pos1" required
style="width: 40px"><br> style="width: 40px"><br>
{% if text1["bold"]%}
Bold: <input type="checkbox" name="bold1" value="bold1" checked>
{% else %}
Bold: <input type="checkbox" name="bold1" value="bold1">
{% endif %}
<h2>Bottom text</h2> <h2>Bottom text</h2>
Text:<br> Text:<br>
@ -32,7 +37,12 @@
Size: <input type="number" value="{{text2["size"]}}" name="size2" min="0" required Size: <input type="number" value="{{text2["size"]}}" name="size2" min="0" required
style="width: 40px"><br> style="width: 40px"><br>
Y position: <input type="number" value="{{text2["pos"]}}" name="pos2" required Y position: <input type="number" value="{{text2["pos"]}}" name="pos2" required
style="width: 40px"> style="width: 40px"><br>
{% if text2["bold"]%}
Bold: <input type="checkbox" name="bold2" value="bold2" checked>
{% else %}
Bold: <input type="checkbox" name="bold2" value="bold2">
{% endif %}
<h2>Font</h2> <h2>Font</h2>
<label for="font">Font:</label> <label for="font">Font:</label>