From 9de5ba5524907e9b5f370ab396323a4a4a0e669c Mon Sep 17 00:00:00 2001 From: TT-392 Date: Thu, 9 Oct 2025 14:02:05 +0000 Subject: [PATCH] Implement a checkbox to choose if the text will be bold or not --- app.py | 22 +++++++++++++++------- fonts.py | 12 +++++++----- gen_image.py | 5 ++--- templates/text.html | 12 +++++++++++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index 3576714..5ca7827 100644 --- a/app.py +++ b/app.py @@ -24,12 +24,14 @@ templates = { "text1": { "string": "Do Not Hack", "size": 130, - "pos": 0 + "pos": 0, + "bold": True }, "text2": { "string": "bottom text", "size": 50, - "pos": 130 + "pos": 130, + "bold": False }, "cut": True }, @@ -37,12 +39,14 @@ templates = { "text1": { "string": "Nickname", "size": 130, - "pos": 0 + "pos": 0, + "bold": True }, "text2": { "string": "", "size": 50, - "pos": 130 + "pos": 130, + "bold": False }, "cut": True }, @@ -50,12 +54,14 @@ templates = { "text1": { "string": "Remove by", "size": 130, - "pos": 0 + "pos": 0, + "bold": True }, "text2": { "string": "", "size": 50, - "pos": 130 + "pos": 130, + "bold": False }, "cut": True } @@ -178,11 +184,13 @@ def text_form(): "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, } # Clear previously saved font @@ -262,5 +270,5 @@ def user_data(filename): if __name__ == "__main__": - app.run(debug=False) + app.run(debug=True) diff --git a/fonts.py b/fonts.py index 7390843..8dcd600 100644 --- a/fonts.py +++ b/fonts.py @@ -1,8 +1,9 @@ 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.path = path self.stroke_width = stroke_width + self.stroke_width_bold = stroke_width_bold self.selected = default def to_dict(self): @@ -10,12 +11,13 @@ class Font: "name": self.name, "path": self.path, "selected": self.selected, - "stroke_width": self.stroke_width + "stroke_width": self.stroke_width, + "stroke_width_bold": self.stroke_width_bold } def fonts(): return { - "CYBER": Font("CYBER", "resources/OCRAEXT.TTF", 3, True).to_dict(), - "ComicMono": Font("Comic Sans Mono", "resources/ComicMono.ttf", 0).to_dict(), - "EstupidoEspezial": Font("¡¡¡Estupido-Espezial!!!", "resources/Estupido Espezial.ttf", 1).to_dict() + "CYBER": Font("CYBER", "resources/OCRAEXT.TTF", 0, 3, True).to_dict(), + "ComicMono": Font("Comic Sans Mono", "resources/ComicMono.ttf", 0, 2).to_dict(), + "EstupidoEspezial": Font("¡¡¡Estupido-Espezial!!!", "resources/Estupido Espezial.ttf", 0, 2).to_dict() } diff --git a/gen_image.py b/gen_image.py index ba060e2..39c82fc 100644 --- a/gen_image.py +++ b/gen_image.py @@ -32,9 +32,8 @@ def gen_image(height, text1, text2, font): img = Image.new('1', (width, height), color=1) draw = ImageDraw.Draw(img) - - 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) + 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, text2["pos"]), text2["string"], font=font2, stroke_width = font["stroke_width_bold"] if text2["bold"] else font["stroke_width"], stroke_fill="black") if (width > max_label_length): diff --git a/templates/text.html b/templates/text.html index cec6e68..7a985a7 100644 --- a/templates/text.html +++ b/templates/text.html @@ -25,6 +25,11 @@ style="width: 40px">
Y position:
+ {% if text1["bold"]%} + Bold: + {% else %} + Bold: + {% endif %}

Bottom text

Text:
@@ -32,7 +37,12 @@ Size:
Y position: + style="width: 40px">
+ {% if text2["bold"]%} + Bold: + {% else %} + Bold: + {% endif %}

Font