code cleaning

This commit is contained in:
klemek
2020-04-27 11:49:47 +02:00
parent a341fd517f
commit b14793618d
7 changed files with 8 additions and 40 deletions
+1 -1
View File
@@ -12,8 +12,8 @@ from meme_otron import img_factory as imgf
from meme_otron import meme_db as db
from meme_otron import utils
from meme_otron import meme_otron
from meme_otron import VERSION
VERSION = "1.2-dev"
DOC_URL = "https://github.com/klemek/meme-otron/tree/master/docs/README.md"
t0 = datetime.now()
logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO)
+1
View File
@@ -0,0 +1 @@
VERSION = "1.2-dev"
+5 -1
View File
@@ -5,13 +5,17 @@ import os
from . import img_factory as imgf
from . import meme_db as db
from . import meme_otron
from . import VERSION
if __name__ == "__main__":
db.load_memes()
imgf.load_fonts()
# TODO better arguments reading (-h, -o, -v)
if len(sys.argv) <= 1 or sys.argv[1].lower().strip() == "help" or "-h" in sys.argv:
print("python -m meme_otron -h\n"
print(f"Meme-Otron v{VERSION}"
"python -m meme_otron -h\n"
"python -m meme_otron (meme_id) \"[text 1]\" \"[text 2]\" ... > file.jpg\n"
"python -m meme_otron -o file.jpg (meme_id) \"[text 1]\" \"[text 2]\" ...",
file=sys.stderr)
+1 -11
View File
@@ -14,9 +14,6 @@ logger = logging.getLogger("img_factory")
def load_fonts():
"""
TODO
"""
for file in [f for f in os.listdir(FONT_DIR) if path.isfile(path.join(FONT_DIR, f))]:
split = path.splitext(file)
if split[-1] == ".ttf":
@@ -29,8 +26,6 @@ def load_fonts():
def make(template, texts, debug=False):
"""
TODO
:param (str) template:
:param (list of Text) texts:
:param (bool) debug:
@@ -52,15 +47,11 @@ def make(template, texts, debug=False):
def draw_text(draw, img, text, debug=False):
"""
TODO
:param (PIL.ImageDraw.ImageDraw) draw: source image canvas
:param (PIL.Image.Image) img: source image
:param (Text) text:
:param (bool) debug:
"""
# TODO rotation
# https://stackoverflow.com/questions/245447/how-do-i-draw-text-at-an-angle-using-pythons-pil
if text.text is not None and len(text.text.strip()) > 0:
text.init() # load default values
if text.font in FONTS:
@@ -100,6 +91,7 @@ def fit_text(size, text):
:rtype: (str, PIL.ImageFont.FreeTypeFont)
:return:
"""
# TODO rework this function
max_width = round(size[0] * (text.x_range[1] - text.x_range[0]))
max_height = round(size[1] * (text.y_range[1] - text.y_range[0]))
text_size = None
@@ -126,8 +118,6 @@ def fit_text(size, text):
def get_pos(size, text, font, relative=False):
"""
TODO
:param (int,int) size: source image size
:param (Text) text:
:param (PIL.ImageFont.FreeTypeFont) font:
-8
View File
@@ -15,8 +15,6 @@ logger = logging.getLogger("meme_db")
def load_memes(purge=False):
"""
TODO
:param (bool) purge:
"""
global DATA, ALIASES
@@ -41,8 +39,6 @@ def load_memes(purge=False):
def load_item(i, item):
"""
TODO
:param (int) i:
:param (dict) item:
"""
@@ -123,8 +119,6 @@ def load_item(i, item):
def load_text(c, raw_text, text=None):
"""
TODO
:param (int) c:
:param (dict) raw_text:
:param (Text|None) text:
@@ -158,8 +152,6 @@ def load_text(c, raw_text, text=None):
def get_meme(name):
"""
TODO
:param (str) name:
:rtype: Meme|None
:return:
-4
View File
@@ -23,8 +23,6 @@ left_wmark.y_range = [0.005, 0.995]
def parse_text(s):
"""
TODO
:param (str) s:
:rtype: str
"""
@@ -33,8 +31,6 @@ def parse_text(s):
def compute(*args, left_wmark_text=None, debug=False):
"""
TODO
:param (str) left_wmark_text:
:param (bool) debug:
:param (str) args:
-15
View File
@@ -6,9 +6,6 @@ DEFAULT_FONT_SIZE = 0.05
class Pos(IntEnum):
"""
TODO
"""
NW = 0
N = 1
NE = 2
@@ -21,10 +18,6 @@ class Pos(IntEnum):
class Meme:
"""
TODO
"""
def __init__(self, meme_id):
self.id = meme_id
self.aliases = []
@@ -40,9 +33,6 @@ class Meme:
class Text:
"""
TODO
"""
base_properties = ["font", "font_size", "fill", "stroke_width",
"stroke_fill", "align", "position"]
@@ -68,8 +58,6 @@ class Text:
def update(self, base):
"""
TODO
:param (Text) base:
"""
for prop in Text.base_properties:
@@ -77,9 +65,6 @@ class Text:
setattr(self, prop, getattr(base, prop))
def init(self):
"""
TODO
"""
if self.x_range is None:
self.x_range = (0, 1)
if self.y_range is None: