more templates + db improvements
This commit is contained in:
@@ -131,18 +131,18 @@ def get_pos(size, text, font):
|
||||
pos_y = 0
|
||||
text_size = font.getsize_multiline(text.text, stroke_width=text.stroke_width * font.size)
|
||||
|
||||
if text.position.value[0] == "S":
|
||||
if int(text.position.value) // 3 == 0:
|
||||
pos_y = min_y
|
||||
elif text.position.value[0] == "C":
|
||||
elif int(text.position.value) // 3 == 1:
|
||||
pos_y = round((min_y + max_y) / 2 - text_size[1] / 2)
|
||||
elif text.position.value[0] == "N":
|
||||
else:
|
||||
pos_y = max_y - text_size[1]
|
||||
|
||||
if text.position.value[1] == "W":
|
||||
if int(text.position.value) % 3 == 0:
|
||||
pos_x = min_x
|
||||
elif text.position.value[1] == "C":
|
||||
elif int(text.position.value) % 3 == 1:
|
||||
pos_x = round((min_x + max_x) / 2 - text_size[0] / 2)
|
||||
elif text.position.value[1] == "E":
|
||||
else:
|
||||
pos_x = max_x - text_size[0]
|
||||
|
||||
return pos_x, pos_y
|
||||
|
||||
@@ -96,7 +96,10 @@ def load_item(i, item):
|
||||
else:
|
||||
DATA[item_id] = Meme(item_id, aliases, abstract, template, font, font_size, texts)
|
||||
for alias in aliases:
|
||||
ALIASES[alias] = item_id
|
||||
if alias in ALIASES:
|
||||
logger.warning(f"Item '{item_id}'({i}): alias '{alias}' already registered by '{ALIASES[alias]}'")
|
||||
else:
|
||||
ALIASES[alias] = item_id
|
||||
logger.info(f"Loaded meme '{item_id}' with {len(texts)} texts")
|
||||
except KeyError as e:
|
||||
logger.warning(f"Item '{item_id}'({i}): key {e} not found")
|
||||
@@ -142,7 +145,7 @@ def load_text(j, raw_text):
|
||||
if "fill" in raw_text:
|
||||
if not (utils.is_list_of(raw_text["fill"], [int], 3)):
|
||||
raise TypeError(f"'fill' is not a list of 3 int")
|
||||
text.fill = raw_text["fill"]
|
||||
text.fill = tuple(raw_text["fill"])
|
||||
if "stroke_width" in raw_text:
|
||||
if not (isinstance(raw_text["stroke_width"], float)):
|
||||
raise TypeError(f"'stroke_width' is not a float")
|
||||
@@ -150,7 +153,7 @@ def load_text(j, raw_text):
|
||||
if "stroke_fill" in raw_text:
|
||||
if not (utils.is_list_of(raw_text["stroke_fill"], [int], 3)):
|
||||
raise TypeError(f"'stroke_fill' is not a list of 3 int")
|
||||
text.stroke_fill = raw_text["stroke_fill"]
|
||||
text.stroke_fill = tuple(raw_text["stroke_fill"])
|
||||
if "align" in raw_text:
|
||||
if raw_text["align"] not in ["left", "center", "right"]:
|
||||
raise TypeError(f"'align' is not 'left', 'center' or 'right'")
|
||||
|
||||
+23
-13
@@ -1,20 +1,20 @@
|
||||
from enum import Enum
|
||||
from enum import IntEnum
|
||||
import copy
|
||||
|
||||
|
||||
class Pos(Enum):
|
||||
class Pos(IntEnum):
|
||||
"""
|
||||
TODO
|
||||
"""
|
||||
NW = "NW"
|
||||
N = "NC"
|
||||
NE = "NE"
|
||||
W = "CW"
|
||||
CENTER = "CC"
|
||||
E = "CE"
|
||||
SW = "NW"
|
||||
S = "NC"
|
||||
SE = "NE"
|
||||
NW = 0
|
||||
N = 1
|
||||
NE = 2
|
||||
W = 3
|
||||
CENTER = 4
|
||||
E = 5
|
||||
SW = 6
|
||||
S = 7
|
||||
SE = 8
|
||||
|
||||
|
||||
class Meme:
|
||||
@@ -51,12 +51,22 @@ class Text:
|
||||
|
||||
def __init__(self, text=None):
|
||||
self.text = text
|
||||
|
||||
self.x_range = (0, 1)
|
||||
self.y_range = (0, 1)
|
||||
self.position = Pos.CENTER
|
||||
|
||||
self.font = None
|
||||
self.font_size = None
|
||||
|
||||
self.fill = (0, 0, 0)
|
||||
self.stroke_width = 0
|
||||
self.stroke_fill = (0, 0, 0)
|
||||
self.font = None
|
||||
|
||||
self.align = "center"
|
||||
self.position = Pos.CENTER
|
||||
|
||||
def update(self, base):
|
||||
for prop in ["font", "font_size", "fill", "stroke_width",
|
||||
"stroke_fill", "align", "position"]:
|
||||
if getattr(self, prop) is None:
|
||||
setattr(self,prop, getattr(base, prop))
|
||||
|
||||
Reference in New Issue
Block a user