Implement a checkbox to choose if the text will be bold or not
This commit is contained in:
parent
3d572fd060
commit
9de5ba5524
4 changed files with 35 additions and 16 deletions
22
app.py
22
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)
|
||||
|
||||
|
|
|
|||
12
fonts.py
12
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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@
|
|||
style="width: 40px"><br>
|
||||
Y position: <input type="number" value="{{text1["pos"]}}" name="pos1" required
|
||||
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>
|
||||
Text:<br>
|
||||
|
|
@ -32,7 +37,12 @@
|
|||
Size: <input type="number" value="{{text2["size"]}}" name="size2" min="0" required
|
||||
style="width: 40px"><br>
|
||||
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>
|
||||
<label for="font">Font:</label>
|
||||
|
|
|
|||
Loading…
Reference in a new issue