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