Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No effect with opacity in draw operator #7301

Closed
Watson1978 opened this issue May 9, 2024 · 5 comments
Closed

No effect with opacity in draw operator #7301

Watson1978 opened this issue May 9, 2024 · 5 comments

Comments

@Watson1978
Copy link

Watson1978 commented May 9, 2024

ImageMagick version

7.1.1-29

Operating system

Other (enter below)

Operating system, version and so on

Linux 6.8.8, macOS 14.4.1

Description

I think the opacity in draw operator should effect the image as same as when using fill_opacity and stroke_opacity in draw operator.
In fact, it is implemented as such.

ImageMagick/MagickCore/draw.c

Lines 3228 to 3253 in b9dc200

if (LocaleCompare("opacity",keyword) == 0)
{
double
opacity;
(void) GetNextToken(q,&q,extent,token);
if (graphic_context[n]->clip_path != MagickFalse)
break;
factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
opacity=MagickMin(MagickMax(factor*
GetDrawValue(token,&next_token),0.0),1.0);
if (token == next_token)
ThrowPointExpectedException(token,exception);
if (graphic_context[n]->compliance == SVGCompliance)
{
graphic_context[n]->fill_alpha*=opacity;
graphic_context[n]->stroke_alpha*=opacity;
}
else
{
graphic_context[n]->fill_alpha=(double) QuantumRange*opacity;
graphic_context[n]->stroke_alpha=(double) QuantumRange*opacity;
}
break;
}
status=MagickFalse;

However, it doesn't work with recently ImageMagick 6 and 7.

Steps to Reproduce

~/imagemagick7.1/bin/convert -size 420x120 xc:gray \
  -draw "stroke 'blue'; fill 'yellow'; \
         stroke-width 10; \
         opacity  25%; roundrectangle  20,20, 100,100,5,5; \
         opacity  50%; roundrectangle 120,20, 200,100,5,5; \
         opacity  75%; roundrectangle 220,20, 300,100,5,5; \
         opacity 100%; roundrectangle 320,20, 400,100,5,5; " \
  result_7_1.png

If I ran above command with ImageMagick 6.8.9-10, it works as expected.

Images

ImageMagick 6.8 ImageMagick 6.9 ImageMagick 7.1
@fmw42
Copy link

fmw42 commented May 9, 2024

I confirm, when I do your command on IM 7.1.1.32 Mac OSX Ventura, I get an image with an opaque alpha set on the result. But none of the drawn features show the specified opacity.

magick -size 420x120 xc:gray \
-draw "stroke blue fill yellow \
stroke-width 10 \
opacity  25% roundrectangle  20,20 100,100 5,5 \
opacity  50% roundrectangle 120,20 200,100 5,5 \
opacity  75% roundrectangle 220,20 300,100 5,5 \
opacity 100% roundrectangle 320,20 400,100 5,5" \
result_7_1.png

result_7_1

@dlemstra dlemstra reopened this May 9, 2024
@dlemstra
Copy link
Member

dlemstra commented May 9, 2024

I just pushed a patch to solve this issue in IM7. But we are getting a different (correct) output compared to 6.8:
z

@fmw42
Copy link

fmw42 commented May 9, 2024

Is that the IM 7 new result or the IM 6 result? Can you show both?

@dlemstra
Copy link
Member

dlemstra commented May 9, 2024

I haven't found a proper fix for IM6 yet and this is the IM7 result.

@Watson1978
Copy link
Author

Seems this issue has been solved at 6.9.13-11 and 7.1.1-33. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants