Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions py/drop_shadow_v3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from PIL import Image
from .imagefunc import log, tensor2pil, pil2tensor, image2mask, mask2image
from .imagefunc import chop_image_v2, chop_mode_v2, shift_image, expand_mask
from .imagefunc import chop_image_v3, chop_mode_v2, shift_image, expand_mask



Expand Down Expand Up @@ -41,6 +41,7 @@ def drop_shadow_v2(self, layer_image, invert_mask, blend_mode, opacity,
background_image=None, layer_mask=None
):

background_image_was_provided = background_image is not None
# If background image is empty, create transparent background image for each layer image
if background_image == None:
background_image = []
Expand Down Expand Up @@ -94,7 +95,7 @@ def drop_shadow_v2(self, layer_image, invert_mask, blend_mode, opacity,
shadow_mask = expand_mask(image2mask(__mask), grow, blur) #扩张,模糊
# 合成阴影
alpha = tensor2pil(shadow_mask).convert('L')
_shadow = chop_image_v2(_canvas, shadow_color, blend_mode, opacity)
_shadow = chop_image_v3(_canvas, shadow_color, blend_mode, opacity, not background_image_was_provided)
_canvas.paste(_shadow, mask=alpha)
# 合成layer
_canvas.paste(_layer, mask=_mask)
Expand All @@ -111,4 +112,4 @@ def drop_shadow_v2(self, layer_image, invert_mask, blend_mode, opacity,

NODE_DISPLAY_NAME_MAPPINGS = {
"LayerStyle: DropShadow V3": "LayerStyle: DropShadow V3"
}
}
10 changes: 10 additions & 0 deletions py/imagefunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ def chop_image_v2(background_image:Image, layer_image:Image, blend_mode:str, opa

return Image.fromarray(np.uint8(blended_np)).convert('RGB')

def chop_image_v3(background_image:Image, layer_image:Image, blend_mode:str, opacity:int, alpha:bool) -> Image:

backdrop_prepped = np.asarray(background_image.convert('RGBA'), dtype=float)
source_prepped = np.asarray(layer_image.convert('RGBA'), dtype=float)
blended_np = BLEND_MODES[blend_mode](backdrop_prepped, source_prepped, opacity / 100)

if alpha:
return Image.fromarray(np.uint8(blended_np)).convert('RGBA')
return Image.fromarray(np.uint8(blended_np)).convert('RGB')

def remove_background(image:Image, mask:Image, color:str) -> Image:
width = image.width
height = image.height
Expand Down