Skip to content

Commit

Permalink
feat: add meme thermometer_gun (#158)
Browse files Browse the repository at this point in the history
* 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
3 people authored Sep 3, 2024
1 parent a09ad9d commit 5f8402d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions meme_generator/memes/thermometer_gun/__init__.py
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.

0 comments on commit 5f8402d

Please sign in to comment.