more templates + db improvements
@@ -5,21 +5,27 @@ from meme_otron import img_factory as imgf
|
||||
from meme_otron import meme_db
|
||||
from meme_otron import utils
|
||||
|
||||
logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.DEBUG)
|
||||
logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.WARNING)
|
||||
|
||||
imgf.load_fonts()
|
||||
meme_db.load_memes()
|
||||
|
||||
dst_dir = utils.relative_path(__file__, "templates")
|
||||
|
||||
templates_dir = utils.relative_path(__file__, "..", "templates")
|
||||
|
||||
for f in os.listdir(dst_dir):
|
||||
if path.isfile(path.join(dst_dir, f)):
|
||||
os.unlink(path.join(dst_dir, f))
|
||||
|
||||
count = 0
|
||||
|
||||
for meme_id in meme_db.DATA:
|
||||
meme = meme_db.get_meme(meme_id)
|
||||
if meme is not None:
|
||||
img = imgf.make(meme.template, meme.texts, debug=True)
|
||||
if img is not None:
|
||||
img.save(path.join(dst_dir, meme.template))
|
||||
print(meme_id)
|
||||
count += 1
|
||||
|
||||
print(f"{count} registered templates / {len(os.listdir(templates_dir))} files")
|
||||
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 40 KiB |
@@ -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,6 +96,9 @@ def load_item(i, item):
|
||||
else:
|
||||
DATA[item_id] = Meme(item_id, aliases, abstract, template, font, font_size, texts)
|
||||
for alias in aliases:
|
||||
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:
|
||||
@@ -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'")
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -122,6 +122,24 @@
|
||||
"x_range": [0.02, 0.48],
|
||||
"y_range": [0.80, 1.00]
|
||||
}]
|
||||
},{
|
||||
"id": "2_texts",
|
||||
"abstract": true,
|
||||
"font": "impact",
|
||||
"font_size": 0.12,
|
||||
"texts": [{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.02, 0.50],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "N"
|
||||
},{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.50, 0.98],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
}]
|
||||
},{
|
||||
"id": "drake",
|
||||
"template": "drake.jpg",
|
||||
@@ -180,4 +198,110 @@
|
||||
"id": "winnie3",
|
||||
"template": "winnie3.jpg",
|
||||
"based_on": "3_panel_right"
|
||||
},{
|
||||
"id": "burn",
|
||||
"template": "burn.jpg",
|
||||
"font": "arial",
|
||||
"texts": [{
|
||||
"x_range": [0.08, 0.37],
|
||||
"y_range": [0.09, 0.43]
|
||||
},{
|
||||
"x_range": [0.65, 0.95],
|
||||
"y_range": [0.21, 0.40],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1
|
||||
},{
|
||||
"x_range": [0.16, 0.45],
|
||||
"y_range": [0.73, 0.91],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1
|
||||
},{
|
||||
"x_range": [0.69, 0.98],
|
||||
"y_range": [0.72, 0.90],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1
|
||||
}]
|
||||
},{
|
||||
"id": "aliens",
|
||||
"template": "aliens.jpg",
|
||||
"font": "impact",
|
||||
"font_size": 0.15,
|
||||
"texts": [{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.8, 0.98],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
}]
|
||||
},{
|
||||
"id": "grandma",
|
||||
"template": "grandma.jpg",
|
||||
"based_on": "2_texts"
|
||||
},{
|
||||
"id": "everywhere",
|
||||
"template": "everywhere.jpg",
|
||||
"aliases": ["buzz", "woody"],
|
||||
"based_on": "2_texts"
|
||||
},{
|
||||
"id": "bender",
|
||||
"template": "bender.jpg",
|
||||
"aliases": ["hookers", "blackjack"],
|
||||
"based_on": "2_texts"
|
||||
},{
|
||||
"id": "alive",
|
||||
"template": "alive.jpg",
|
||||
"aliases": ["no_brain"],
|
||||
"font": "grafo",
|
||||
"font_size": 0.07,
|
||||
"texts": [{
|
||||
"x_range": [0.05, 0.45],
|
||||
"y_range": [0.53, 0.70],
|
||||
"fill": [0, 14, 109],
|
||||
"stroke_fill": [0, 14, 109],
|
||||
"stroke_width": 0.02
|
||||
}]
|
||||
},{
|
||||
"id": "argument",
|
||||
"template": "argument.jpg",
|
||||
"aliases": ["wrestlers"],
|
||||
"font": "impact",
|
||||
"font_size": 0.07,
|
||||
"texts": [{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.10, 0.19],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
},{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.30, 0.39],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
},{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.50, 0.59],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
},{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.70, 0.79],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
},{
|
||||
"x_range": [0.02, 0.98],
|
||||
"y_range": [0.90, 0.99],
|
||||
"stroke_fill": [255, 255, 255],
|
||||
"stroke_width": 0.1,
|
||||
"position": "S"
|
||||
}]
|
||||
},{
|
||||
"id": "buff",
|
||||
"template": "buff.jpg",
|
||||
"aliases": ["tom", "jerry"],
|
||||
"font": "impact",
|
||||
"font_size": 0.07,
|
||||
"texts": []
|
||||
}]
|
||||
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 88 KiB |