Skip to content

Commit

Permalink
Upgrade: 新增表情包奖状模板, fix typo
Browse files Browse the repository at this point in the history
- 新增表情包奖状模板
- Fix typo
  • Loading branch information
Ailitonia committed Oct 7, 2021
1 parent ffc0507 commit 53a6683
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 62 deletions.
5 changes: 3 additions & 2 deletions omega_miya/plugins/sticker_maker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from nonebot.plugin.export import export
from nonebot.typing import T_State
from nonebot.adapters.cqhttp.bot import Bot
from nonebot.adapters.cqhttp.event import MessageEvent, GroupMessageEvent, PrivateMessageEvent
from nonebot.adapters.cqhttp.event import MessageEvent, GroupMessageEvent
from nonebot.adapters.cqhttp.permission import GROUP, PRIVATE_FRIEND
from nonebot.adapters.cqhttp import MessageSegment
from omega_miya.utils.omega_plugin_utils import init_export, init_processor_state, PicEncoder
from omega_miya.utils.omega_plugin_utils import init_export, init_processor_state
from .utils import sticker_maker_main


Expand Down Expand Up @@ -83,6 +83,7 @@ async def handle_sticker(bot: Bot, event: MessageEvent, state: T_State):
'鲁迅写': {'name': 'luxunxie', 'type': 'static', 'text_part': 1, 'help_msg': '该模板字数限制100(x)'},
'记仇': {'name': 'jichou', 'type': 'static', 'text_part': 1, 'help_msg': '该模板字数限制100(x)'},
'ph': {'name': 'phlogo', 'type': 'static', 'text_part': 1, 'help_msg': '两部分文字中间请用空格隔开'},
'奖状': {'name': 'jiangzhuang', 'type': 'static', 'text_part': 1, 'help_msg': '该模板字数限制100(x)'},
'petpet': {'name': 'petpet', 'type': 'gif', 'text_part': 0, 'help_msg': '最好使用长宽比接近正方形的图片'}
}

Expand Down
9 changes: 6 additions & 3 deletions omega_miya/plugins/sticker_maker/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:
'luxunxie': stick_maker_static_luxun,
'jichou': stick_maker_static_jichou,
'phlogo': stick_maker_static_phlogo,
'jiangzhuang': stick_maker_static_jiangzhuang,
'petpet': stick_maker_temp_petpet
}

Expand All @@ -48,6 +49,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:
'luxunxie': 'SourceHanSans_Regular.otf',
'jichou': 'SourceHanSans_Regular.otf',
'phlogo': 'SourceHanSans_Heavy.otf',
'jiangzhuang': 'HanYiWeiBeiJian.ttf',
'petpet': 'SourceHanSans_Regular.otf'
}

Expand All @@ -64,6 +66,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:
'luxunxie': 512,
'jichou': 512,
'phlogo': 512,
'jiangzhuang': 1024,
'petpet': 512
}

Expand Down Expand Up @@ -107,7 +110,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:

# 调用模板处理图片
made_image = await stick_maker[temp](text=text, image_file=make_image, font_path=font_path,
image_wight=image_resize_width, image_height=image_resize_height)
image_width=image_resize_width, image_height=image_resize_height)

# 输出图片
made_image.save(sticker_path, 'JPEG')
Expand Down Expand Up @@ -136,7 +139,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:

# 调用模板处理图片
make_image = await stick_maker[temp](text=text, image_file=make_image, font_path=font_path,
image_wight=image_resize_width, image_height=image_resize_height)
image_width=image_resize_width, image_height=image_resize_height)

# 输出图片
make_image.save(sticker_path, 'JPEG')
Expand Down Expand Up @@ -168,7 +171,7 @@ async def sticker_maker_main(url: str, temp: str, text: str, sticker_temp_type:

# 调用模板处理图片
made_image = await stick_maker[temp](text=text, image_file=make_image, font_path=font_path,
image_wight=image_resize_width, image_height=image_resize_height,
image_width=image_resize_width, image_height=image_resize_height,
temp_path=gif_temp_path)

if not made_image:
Expand Down
50 changes: 25 additions & 25 deletions omega_miya/plugins/sticker_maker/utils/default_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@


async def stick_maker_temp_default(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
默认加字表情包模板
"""
def __handle() -> Image.Image:
# 处理图片
draw = ImageDraw.Draw(image_file)
font_size = image_wight // 8
font_size = image_width // 8
text_stroke_width = int(font_size / 20)
font = ImageFont.truetype(font_path, font_size)

text_w, text_h = font.getsize_multiline(text, stroke_width=text_stroke_width)
while text_w >= int(image_wight * 0.95):
while text_w >= int(image_width * 0.95):
font_size = font_size * 7 // 8
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text, stroke_width=text_stroke_width)
# 计算居中文字位置
text_coordinate = (image_wight // 2, 9 * (image_height - text_h) // 10)
text_coordinate = (image_width // 2, 9 * (image_height - text_h) // 10)
draw.multiline_text(xy=text_coordinate,
text=text,
font=font, fill=(255, 255, 255),
Expand All @@ -37,18 +37,18 @@ def __handle() -> Image.Image:


async def stick_maker_temp_littleangel(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
小天使表情包模板
"""
def __handle() -> Image.Image:
# 处理图片
background_w = image_wight + 100
background_w = image_width + 100
background_h = image_height + 240
background = Image.new(mode="RGB", size=(background_w, background_h), color=(255, 255, 255))
# 处理粘贴位置 上留110像素,下留130像素
image_coordinate = (((background_w - image_wight) // 2), 110)
image_coordinate = (((background_w - image_width) // 2), 110)
background.paste(image_file, image_coordinate)
draw = ImageDraw.Draw(background)

Expand Down Expand Up @@ -83,26 +83,26 @@ def __handle() -> Image.Image:


async def stick_maker_temp_whitebg(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
白底加字表情包模板
"""
def __handle() -> Image.Image:
# 处理文本
if image_wight > image_height:
if image_width > image_height:
font_size = 72
else:
font_size = 84
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text)
while text_w >= (image_wight * 8 // 9):
while text_w >= (image_width * 8 // 9):
font_size = font_size * 7 // 8
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text)

# 处理图片
background_w = image_wight
background_w = image_width
background_h = image_height + round(text_h * 1.5)
background = Image.new(mode="RGB", size=(background_w, background_h), color=(255, 255, 255))

Expand All @@ -122,32 +122,32 @@ def __handle() -> Image.Image:


async def stick_maker_temp_blackbg(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
黑边加底字表情包模板
"""
def __handle() -> Image.Image:
# 处理文本
if image_wight > image_height:
if image_width > image_height:
font_size = 96
else:
font_size = 108
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text)
while text_w >= (image_wight * 9 // 10):
while text_w >= (image_width * 9 // 10):
font_size = font_size * 8 // 9
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text)

# 处理图片
background_w = image_wight + 150
background_w = image_width + 150
background_h = image_height + 115 + round(text_h * 1.5)
background = Image.new(mode="RGB", size=(background_w, background_h), color=(0, 0, 0))
layer_1 = Image.new(mode="RGB", size=(image_wight + 12, image_height + 12), color=(255, 255, 255))
layer_2 = Image.new(mode="RGB", size=(image_wight + 10, image_height + 10), color=(0, 0, 0))
layer_3 = Image.new(mode="RGB", size=(image_wight + 6, image_height + 6), color=(255, 255, 255))
layer_4 = Image.new(mode="RGB", size=(image_wight + 4, image_height + 4), color=(0, 0, 0))
layer_1 = Image.new(mode="RGB", size=(image_width + 12, image_height + 12), color=(255, 255, 255))
layer_2 = Image.new(mode="RGB", size=(image_width + 10, image_height + 10), color=(0, 0, 0))
layer_3 = Image.new(mode="RGB", size=(image_width + 6, image_height + 6), color=(255, 255, 255))
layer_4 = Image.new(mode="RGB", size=(image_width + 4, image_height + 4), color=(0, 0, 0))

# 处理粘贴位置 留出黑边距离
background.paste(layer_1, (70, 70))
Expand All @@ -170,7 +170,7 @@ def __handle() -> Image.Image:


async def stick_maker_temp_decolorize(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
去色加字表情包模板
Expand All @@ -186,7 +186,7 @@ def __handle() -> Image.Image:


async def stick_maker_temp_grass_ja(
text: str, image_file: Image.Image, font_path: str, image_wight: int, image_height: int,
text: str, image_file: Image.Image, font_path: str, image_width: int, image_height: int,
*args, **kwargs) -> Image.Image:
"""
生草日语表情包模板
Expand All @@ -198,23 +198,23 @@ async def stick_maker_temp_grass_ja(
text_ = f'{text_zh}\n{text_ja}'

# 处理黑白
image_file_ = await stick_maker_temp_decolorize(text, image_file, font_path, image_wight, image_height)
image_file_ = await stick_maker_temp_decolorize(text, image_file, font_path, image_width, image_height)

def __handle() -> Image.Image:
# 处理文本
if image_wight > image_height:
if image_width > image_height:
font_size = 48
else:
font_size = 60
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text_)
while text_w >= (image_wight * 9 // 10):
while text_w >= (image_width * 9 // 10):
font_size = font_size * 8 // 9
font = ImageFont.truetype(font_path, font_size)
text_w, text_h = font.getsize_multiline(text_)

# 处理图片
background_w = image_wight
background_w = image_width
background_h = image_height + round(text_h * 1.5)
background = Image.new(mode="RGB", size=(background_w, background_h), color=(0, 0, 0))

Expand Down
2 changes: 1 addition & 1 deletion omega_miya/plugins/sticker_maker/utils/gif_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def stick_maker_temp_petpet(
text: str,
image_file: Image.Image,
font_path: str,
image_wight: int,
image_width: int,
image_height: int,
temp_path: str,
*args,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 53a6683

Please sign in to comment.