-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add meme
thermometer_gun
(#158)
* add meme 'infrared_thermometer' * style: auto fix by pre-commit hooks * updata __init__.py and 0.png * updata __init__.py and 0.png * style: auto fix by pre-commit hooks * format code * rename infrared_thermometer to thermometer_gun --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: meetwq <meetwq@gmail.com>
- Loading branch information
1 parent
a09ad9d
commit 5f8402d
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from pil_utils import BuildImage | ||
|
||
from meme_generator import add_meme | ||
from meme_generator.exception import TextOverLength | ||
from meme_generator.utils import make_png_or_gif | ||
|
||
img_dir = Path(__file__).parent / "images" | ||
|
||
defalut_text = "笨蛋" | ||
|
||
|
||
def thermometer_gun(images: list[BuildImage], texts: list[str], args): | ||
text = defalut_text if not len(texts) else texts[0] | ||
text_frame = BuildImage.new("RGBA", (200, 125)) | ||
try: | ||
text_frame.draw_text( | ||
(0, 0, 200, 125), | ||
text, | ||
allow_wrap=True, | ||
max_fontsize=60, | ||
min_fontsize=15, | ||
fontname="FZKaTong-M19S", | ||
lines_align="center", | ||
) | ||
except ValueError: | ||
raise TextOverLength(text) | ||
img_w, img_h = images[0].size | ||
if img_w > img_h: | ||
size = (round(img_h), round(img_h)) | ||
pos = (round(img_w - img_h), 0) | ||
else: | ||
size = (round(img_w), round(img_w)) | ||
pos = (0, round(img_h - img_w)) | ||
frame = ( | ||
BuildImage.open(img_dir / "0.png") | ||
.paste(text_frame, (555, 240), alpha=True) | ||
.resize(size) | ||
) | ||
|
||
def make(imgs: list[BuildImage]) -> BuildImage: | ||
img = imgs[0].convert("RGBA") | ||
return img.paste(frame, pos, alpha=True) | ||
|
||
return make_png_or_gif(images, make) | ||
|
||
|
||
add_meme( | ||
"thermometer_gun", | ||
thermometer_gun, | ||
min_images=1, | ||
max_images=1, | ||
max_texts=1, | ||
min_texts=0, | ||
keywords=["体温枪"], | ||
default_texts=[defalut_text], | ||
date_created=datetime(2024, 9, 3), | ||
date_modified=datetime(2024, 9, 3), | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.