Skip to content

Commit 7863775

Browse files
committed
Negate opacity channel on ImageMagick 7
In ImageMagick 7, the semantics of the opacity channel is flipped.
1 parent ffb9c5e commit 7863775

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

win2xcur/shadow.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
if 'copy_opacity' in COMPOSITE_OPERATORS:
99
COPY_ALPHA = 'copy_opacity' # ImageMagick 6 name
10+
NEEDS_NEGATE = False
1011
else:
1112
COPY_ALPHA = 'copy_alpha' # ImageMagick 7 name
13+
NEEDS_NEGATE = True
1214

1315

1416
def 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

Comments
 (0)