77
88if 'copy_opacity' in COMPOSITE_OPERATORS :
99 COPY_ALPHA = 'copy_opacity' # ImageMagick 6 name
10+ NEEDS_NEGATE = False
1011else :
1112 COPY_ALPHA = 'copy_alpha' # ImageMagick 7 name
13+ NEEDS_NEGATE = True
1214
1315
1416def apply_to_image (image : BaseImage , * , color : str , radius : float , sigma : float , xoffset : float ,
@@ -18,8 +20,14 @@ def apply_to_image(image: BaseImage, *, color: str, radius: float, sigma: float,
1820 new_width = image .width + 3 * xoffset
1921 new_height = image .height + 3 * yoffset
2022
23+ if NEEDS_NEGATE :
24+ channel = image .channel_images ['opacity' ].clone ()
25+ channel .negate ()
26+ else :
27+ channel = image .channel_images ['opacity' ]
28+
2129 opacity = Image (width = new_width , height = new_height , pseudo = 'xc:white' )
22- opacity .composite (image . channel_images [ 'opacity' ] , left = xoffset , top = yoffset )
30+ opacity .composite (channel , left = xoffset , top = yoffset )
2331 opacity .gaussian_blur (radius * image .width , sigma * image .width )
2432 opacity .negate ()
2533 opacity .modulate (50 )
@@ -28,8 +36,8 @@ def apply_to_image(image: BaseImage, *, color: str, radius: float, sigma: float,
2836 shadow .composite (opacity , operator = COPY_ALPHA )
2937
3038 result = Image (width = new_width , height = new_height , pseudo = 'xc:transparent' )
39+ result .composite (shadow )
3140 result .composite (image )
32- result .composite (shadow , operator = 'difference' )
3341
3442 trimmed = result .clone ()
3543 trimmed .trim (color = Color ('transparent' ))
0 commit comments