Spaces:
Sleeping
Sleeping
File size: 1,741 Bytes
1f9a4c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
from typing import List
from pil_utils import BuildImage
from meme_generator import add_meme
from meme_generator.exception import TextOverLength
from meme_generator.utils import run_sync, translate, translate_microsoft
@run_sync
def _dianzhongdian(img: BuildImage, text: str, trans: str):
img = img.convert("L").resize_width(500)
text_img1 = BuildImage.new("RGBA", (500, 60))
text_img2 = BuildImage.new("RGBA", (500, 35))
try:
text_img1.draw_text(
(20, 0, text_img1.width - 20, text_img1.height),
text,
max_fontsize=50,
min_fontsize=25,
fill="white",
)
except ValueError:
raise TextOverLength(text)
try:
text_img2.draw_text(
(20, 0, text_img2.width - 20, text_img2.height),
trans,
max_fontsize=25,
min_fontsize=10,
fill="white",
)
except ValueError:
raise TextOverLength(text)
frame = BuildImage.new("RGBA", (500, img.height + 100), "black")
frame.paste(img, alpha=True)
frame.paste(text_img1, (0, img.height), alpha=True)
frame.paste(text_img2, (0, img.height + 60), alpha=True)
return frame.save_jpg()
async def dianzhongdian(images: List[BuildImage], texts: List[str], args):
if len(texts) == 1:
text = texts[0]
trans = await translate_microsoft(text, lang_to="jp")
else:
text = texts[0]
trans = texts[1]
return await _dianzhongdian(images[0], text, trans)
add_meme(
"dianzhongdian",
dianzhongdian,
min_images=1,
max_images=1,
min_texts=1,
max_texts=2,
default_texts=["救命啊"],
keywords=["入典", "典中典", "黑白草图"],
)
|