阴影修复
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-12-13 18:25:43 +08:00
parent 9148073095
commit 1861cd4f1a

View File

@ -604,20 +604,27 @@ class ImageFilterImplement:
shadow_color = "black") -> Image.Image:
if image.mode != 'RGBA':
image = image.convert('RGBA')
offset = (x_offset, y_offset)
offset = (-x_offset, -y_offset)
# 创建阴影图层
shadow = Image.new('RGBA', image.size, (0,0,0,0))
shadow_rgb = ColorHandle.parse_color(shadow_color)
shadow_draw = Image.new('RGBA', image.size, shadow_rgb + (0,))
alpha = image.split()[3].point(lambda p: int(p * opacity))
shadow.paste(shadow_draw, (0,0), alpha)
shadow = Image.new('RGBA', image.size, (0, 0, 0, 0))
shadow_draw = ImageDraw.Draw(shadow)
shadow_draw.rectangle(
[0, 0, image.size[0], image.size[1]],
fill=(shadow_rgb[0], shadow_rgb[1], shadow_rgb[2], int(255 * opacity))
)
# 应用遮罩
shadow.putalpha(image.split()[-1])
# 移动
shadow = shadow.transform(
shadow.size,
Image.AFFINE,
(1, 0, offset[0], 0, 1, offset[1])
)
# 应用模糊
shadow = shadow.filter(ImageFilter.GaussianBlur(blur))
# 创建结果图像
result = Image.new('RGBA', (image.width + abs(offset[0]), image.height + abs(offset[1])), (0,0,0,0))
shadow_position = (max(offset[0],0), max(offset[1],0))
image_position = (max(-offset[0],0), max(-offset[1],0))
result.paste(shadow, shadow_position, shadow)
result.paste(image, image_position, image)
# 将阴影叠加在原图下方
result = ImageFilterImplement.apply_overlay(shadow, image)
return result