From 1f887aeaf63cbeb34c734b6e877dfa7c784d3e2d Mon Sep 17 00:00:00 2001 From: MixBadGun <1059129006@qq.com> Date: Sat, 13 Dec 2025 18:37:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=81=AE=E7=BD=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/docs/user/fx.txt | 1 + konabot/plugins/fx_process/fx_handle.py | 13 +++++++++++++ konabot/plugins/fx_process/fx_manager.py | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/konabot/docs/user/fx.txt b/konabot/docs/user/fx.txt index 675e379..254ca59 100644 --- a/konabot/docs/user/fx.txt +++ b/konabot/docs/user/fx.txt @@ -73,6 +73,7 @@ fx [滤镜名称] <参数1> <参数2> ... ### 特殊效果滤镜 * ```fx 设置通道 <通道=A>``` * 可用 R、G、B、A。 +* ```fx 设置遮罩``` * ```fx 色键 <目标颜色="rgb(255,0,0)"> <容差=60>``` * ```fx 晃动 <最大偏移量=5> <运动模糊=False>``` * ```fx 动图 <帧率=10>``` diff --git a/konabot/plugins/fx_process/fx_handle.py b/konabot/plugins/fx_process/fx_handle.py index 8c81ec4..577e535 100644 --- a/konabot/plugins/fx_process/fx_handle.py +++ b/konabot/plugins/fx_process/fx_handle.py @@ -1278,6 +1278,19 @@ class ImageFilterImplement: return Image.fromarray(image_arr, 'RGBA') + # 设置遮罩 + def apply_set_mask(image: Image.Image, mask_image: Image.Image) -> Image.Image: + if image.mode != 'RGBA': + image = image.convert('RGBA') + + if mask_image.mode != 'L': + mask_image = mask_image.convert('L') + + # 应用遮罩 + image.putalpha(mask_image.resize(image.size, Image.Resampling.LANCZOS)) + + return image + @staticmethod def generate_empty(image: Image.Image, images: list[Image.Image], width: int = 512, height: int = 512) -> Image.Image: # 生成空白图像 diff --git a/konabot/plugins/fx_process/fx_manager.py b/konabot/plugins/fx_process/fx_manager.py index 44e56bd..af174e7 100644 --- a/konabot/plugins/fx_process/fx_manager.py +++ b/konabot/plugins/fx_process/fx_manager.py @@ -51,6 +51,7 @@ class ImageFilterManager: "形状描边": ImageFilterImplement.apply_shape_stroke, "半调": ImageFilterImplement.apply_halftone, "设置通道": ImageFilterImplement.apply_set_channel, + "设置遮罩": ImageFilterImplement.apply_set_mask, # 图像处理 "存入图像": ImageFilterStorage.store_image, "读取图像": ImageFilterStorage.load_image, @@ -62,7 +63,7 @@ class ImageFilterManager: "混合图像": ImageFilterImplement.apply_blend, "覆盖图像": ImageFilterImplement.apply_overlay, # 生成式 - "覆加颜色": ImageFilterImplement.generate_solid + "覆加颜色": ImageFilterImplement.generate_solid, } generate_filter_map = {