code quality improvement
This commit is contained in:
@@ -68,7 +68,6 @@ def build_text_only(texts: List[Text], debug: bool = False) -> Image.Image:
|
|||||||
range_factor = heights[i] / max_height
|
range_factor = heights[i] / max_height
|
||||||
start = sum(heights[:i]) / max_height
|
start = sum(heights[:i]) / max_height
|
||||||
text.y_range = (start + text.y_range[0] * range_factor, start + text.y_range[1] * range_factor)
|
text.y_range = (start + text.y_range[0] * range_factor, start + text.y_range[1] * range_factor)
|
||||||
pass
|
|
||||||
txt_img = Image.new('RGBA', (TEXT_IMAGE_WIDTH, max_height), (255, 255, 255))
|
txt_img = Image.new('RGBA', (TEXT_IMAGE_WIDTH, max_height), (255, 255, 255))
|
||||||
return apply_texts(txt_img, texts, debug=debug)
|
return apply_texts(txt_img, texts, debug=debug)
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ def load_item(i: int, item: dict):
|
|||||||
meme.texts_len = current_text - 1
|
meme.texts_len = current_text - 1
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
logger.warning(f"Item '{item_id}'({i + 1}) / Text {j + 1}: {e}")
|
logger.warning(f"Item '{item_id}'({i + 1}) / Text {j + 1}: {e}")
|
||||||
for text in meme.texts:
|
for text in meme.texts:
|
||||||
text.update(meme.text_base)
|
text.update(meme.text_base)
|
||||||
else:
|
else:
|
||||||
DATA[item_id] = meme
|
DATA[item_id] = meme
|
||||||
if not meme.abstract:
|
if not meme.abstract:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from typing import Optional, Tuple, List
|
from typing import Optional, Tuple, List
|
||||||
import re
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
|||||||
+11
-8
@@ -8,12 +8,15 @@ try:
|
|||||||
y0 = int(input("y0:"))
|
y0 = int(input("y0:"))
|
||||||
w1 = int(input("w1:"))
|
w1 = int(input("w1:"))
|
||||||
h1 = int(input("h1:"))
|
h1 = int(input("h1:"))
|
||||||
x1 = round(x0/w, 2)
|
x1 = round(x0 / w, 2)
|
||||||
y1 = round(y0/h, 2)
|
y1 = round(y0 / h, 2)
|
||||||
x2 = round((x0+w1)/w, 2)
|
x2 = round((x0 + w1) / w, 2)
|
||||||
y2 = round((y0+h1)/h, 2)
|
y2 = round((y0 + h1) / h, 2)
|
||||||
print(',{\n "x_range": '+f"[{x1:.2f}, {x2:.2f}]"+',\n "y_range": '+f"[{y1:.2f}, {y2:.2f}]"+'\n }')
|
print(
|
||||||
except:
|
',{\n "x_range": ' + f"[{x1:.2f}, {x2:.2f}]" + ',\n "y_range": ' + f"[{y1:.2f}, {y2:.2f}]" + '\n }')
|
||||||
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
except:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|||||||
+2
-3
@@ -3,7 +3,6 @@ import stat
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from os import path
|
|
||||||
from meme_otron import img_factory
|
from meme_otron import img_factory
|
||||||
from meme_otron import meme_db
|
from meme_otron import meme_db
|
||||||
from meme_otron import utils
|
from meme_otron import utils
|
||||||
@@ -16,7 +15,7 @@ db_file = utils.relative_path(__file__, "..", meme_db.DATA_FILE)
|
|||||||
templates_dir = utils.relative_path(__file__, "..", "templates")
|
templates_dir = utils.relative_path(__file__, "..", "templates")
|
||||||
dst_dir = utils.relative_path(__file__, "tmp")
|
dst_dir = utils.relative_path(__file__, "tmp")
|
||||||
|
|
||||||
if not path.exists(dst_dir):
|
if not os.path.exists(dst_dir):
|
||||||
os.mkdir(dst_dir)
|
os.mkdir(dst_dir)
|
||||||
|
|
||||||
last = None
|
last = None
|
||||||
@@ -32,6 +31,6 @@ while True:
|
|||||||
meme = meme_db.get_meme(meme_id)
|
meme = meme_db.get_meme(meme_id)
|
||||||
img = img_factory.build_from_template(meme.template, meme.texts, debug=True)
|
img = img_factory.build_from_template(meme.template, meme.texts, debug=True)
|
||||||
if img is not None:
|
if img is not None:
|
||||||
img.save(path.join(dst_dir, meme.template))
|
img.save(os.path.join(dst_dir, meme.template))
|
||||||
count += 1
|
count += 1
|
||||||
print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")
|
print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")
|
||||||
|
|||||||
Reference in New Issue
Block a user