Skip to content

Commit

Permalink
add 5 memes
Browse files Browse the repository at this point in the history
1.鬼畜(guichu)
2.旅行伙伴觉醒(maimai_awaken)
3.旅行伙伴加入(maimai_join)
4.嘲讽(taunt)
5.我想上的(what_I_want_to_do)
  • Loading branch information
jcjrobert committed Jul 19, 2023
1 parent dbe2642 commit 6ff2e10
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 0 deletions.
107 changes: 107 additions & 0 deletions meme_generator/memes/guichu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from collections import namedtuple
from typing import Dict, List, Literal

from PIL import Image
from PIL.Image import Image as IMG
from pil_utils import BuildImage
from pydantic import Field

from meme_generator import MemeArgsModel, MemeArgsParser, MemeArgsType, add_meme
from meme_generator.utils import save_gif

help = "鬼畜对称方向"

parser = MemeArgsParser(prefix_chars="-/")
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-d",
"--direction",
type=str,
choices=["left", "right", "top", "bottom"],
default="left",
help=help,
)
group.add_argument("--left", "/左", action="store_const", const="left", dest="direction")
group.add_argument(
"--right", "/右", action="store_const", const="right", dest="direction"
)
group.add_argument("--top", "/上", action="store_const", const="top", dest="direction")
group.add_argument(
"--bottom", "/下", action="store_const", const="bottom", dest="direction"
)

class Model(MemeArgsModel):
direction: Literal["left", "right", "top", "bottom"] = Field(
"left", description=help
)

def guichu(images: List[BuildImage], texts, args):
img = images[0].convert("RGBA")
img_w, img_h = img.size

Mode = namedtuple(
"Mode", ["method", "size1", "pos1", "size2", "pos2"]
)
modes: Dict[str, Mode] = {
"left": Mode(
Image.FLIP_LEFT_RIGHT,
(0, 0, img_w // 2, img_h),
(0, 0),
(img_w // 2, 0, img_w // 2 * 2, img_h),
(img_w // 2, 0),
),
"right": Mode(
Image.FLIP_LEFT_RIGHT,
(img_w // 2, 0, img_w // 2 * 2, img_h),
(img_w // 2, 0),
(0, 0, img_w // 2, img_h),
(0, 0),
),
"top": Mode(
Image.FLIP_TOP_BOTTOM,
(0, 0, img_w, img_h // 2),
(0, 0),
(0, img_h // 2, img_w, img_h // 2 * 2),
(0, img_h // 2),
),
"bottom": Mode(
Image.FLIP_TOP_BOTTOM,
(0, img_h // 2, img_w, img_h // 2 * 2),
(0, img_h // 2),
(0, 0, img_w, img_h // 2),
(0, 0),
),
}
mode = modes[args.direction]

img_flip = img.transpose(mode.method)
img_symmetric = BuildImage.new("RGBA", img.size)
img_symmetric.paste(img.crop(mode.size1), mode.pos1, alpha=True)
img_symmetric.paste(img_flip.crop(mode.size2), mode.pos2, alpha=True)
img_symmetric_big = BuildImage.new("RGBA", img.size)
img_symmetric_big.paste(img_symmetric.copy().resize_width(img_w*2), (-img_w // 2, -img_h // 2))

frames: List[IMG] = []
frames += ([img.image] * 3 + [img_flip.image] * 3) * 3 + \
[img.image, img_flip.image] * 3 + \
([img_symmetric.image] * 2 + [img_symmetric_big.image] * 2) * 2

return save_gif(frames, 0.20)

add_meme(
"guichu",
guichu,
min_images=1,
max_images=1,
args_type=MemeArgsType(
parser,
Model,
[
Model(direction="left"),
Model(direction="right"),
Model(direction="top"),
Model(direction="bottom"),
],
),
keywords=["鬼畜"],
)
19 changes: 19 additions & 0 deletions meme_generator/memes/maimai_awaken/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
from typing import List

from meme_generator import add_meme
from pil_utils import BuildImage
from meme_generator.utils import make_jpg_or_gif

img_dir = Path(__file__).parent / "images"

def maimai_awaken(images: List[BuildImage], texts, args):
frame = BuildImage.open(img_dir / "0.png")

def make(img: BuildImage) -> BuildImage:
img = img.convert("RGBA").square().resize((250, 250)).rotate(-25, expand=True)
return frame.copy().paste(img, (134, 134), alpha=True, below=True)

return make_jpg_or_gif(images[0], make)

add_meme("maimai_awaken", maimai_awaken, min_images=1, max_images=1, keywords=["旅行伙伴觉醒"])
Binary file added meme_generator/memes/maimai_awaken/images/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions meme_generator/memes/maimai_join/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
from typing import List

from meme_generator import add_meme
from pil_utils import BuildImage
from meme_generator.utils import make_jpg_or_gif

img_dir = Path(__file__).parent / "images"

def maimai_join(images: List[BuildImage], texts, args):
frame = BuildImage.open(img_dir / "0.png")

def make(img: BuildImage) -> BuildImage:
img = img.convert("RGBA").square().resize((400, 400))
return frame.copy().paste(img, (50, 50), alpha=True, below=True)

return make_jpg_or_gif(images[0], make)

add_meme("maimai_join", maimai_join, min_images=1, max_images=1, keywords=["旅行伙伴加入"])
Binary file added meme_generator/memes/maimai_join/images/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions meme_generator/memes/taunt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
from typing import List

from meme_generator import add_meme
from pil_utils import BuildImage
from meme_generator.utils import make_jpg_or_gif

img_dir = Path(__file__).parent / "images"

def taunt(images: List[BuildImage], texts, args):
frame = BuildImage.open(img_dir / "0.png")

def make(img: BuildImage) -> BuildImage:
img = img.convert("RGBA").square().resize((230, 230))
return frame.copy().paste(img, (245, 245))

return make_jpg_or_gif(images[0], make)

add_meme("taunt", taunt, min_images=1, max_images=1, keywords=["嘲讽"])
Binary file added meme_generator/memes/taunt/images/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions meme_generator/memes/what_I_want_to_do/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
from typing import List

from meme_generator import add_meme
from pil_utils import BuildImage
from meme_generator.utils import make_jpg_or_gif

img_dir = Path(__file__).parent / "images"

def what_I_want_to_do(images: List[BuildImage], texts, args):
frame = BuildImage.open(img_dir / "0.png")

def make(img: BuildImage) -> BuildImage:
img = img.convert("RGBA").circle().resize((270, 270))
return frame.copy().paste(img, (350, 590), alpha=True)

return make_jpg_or_gif(images[0], make)

add_meme("what_I_want_to_do", what_I_want_to_do, min_images=1, max_images=1, keywords=["我想上的"])
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 6ff2e10

Please sign in to comment.