我如何用魔杖绘制颜色和半透明的界线

发布于 2025-02-07 05:47:07 字数 633 浏览 1 评论 0原文

我使用诸如打击之类的代码在我的图片上绘制半透明的黑色框架,边框宽度5像素。

from wand.color import Color
from wand.image import Image
from wand.display import display
from wand.drawing import Drawing

# ... init image

with (Drawing() as draw):
    draw.stroke_width = 5 
    draw.fill_color = Color('transparent')
    draw.stroke_color = Color('rgb(0, 0, 0, 0.5)')
    draw.rectangle(left=frame_offset, top=frame_offset, 
        right=w-frame_offset, bottom=h-frame_offset)

但是颜色('rgb(0,0,0,0.5)')给出了固体黑色边框,而不是预期的半透明。

我在没有成功的情况下尝试了颜色构造器中的alpha设置的某些值,并且在文档中没有关于它的描述。谁能给出一些建议?

I use the code like blow to draw a semi-transparent black frame on my picture, border width 5 pixels.

from wand.color import Color
from wand.image import Image
from wand.display import display
from wand.drawing import Drawing

# ... init image

with (Drawing() as draw):
    draw.stroke_width = 5 
    draw.fill_color = Color('transparent')
    draw.stroke_color = Color('rgb(0, 0, 0, 0.5)')
    draw.rectangle(left=frame_offset, top=frame_offset, 
        right=w-frame_offset, bottom=h-frame_offset)

But the Color('rgb(0, 0, 0, 0.5)') gives a solid black border, not semi-transparent as expected.

I had tried some value of the alpha setting in color constructor without successful, and in document of wand there is no description about it. Can anyone give some advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2025-02-14 05:47:07

rgb颜色定义后,您缺少a。只需将draws.stroke_color属性更新为rgba(0,0,0,0,0.5)

with Image(filename='logo:') as img:
    with Drawing() as ctx:
        ctx.fill_color = 'transparent'
        ctx.stroke_width = 5
        ctx.stroke_color = 'rgba(0, 0, 0, 0.5)'
        ctx.rectangle(left=60, top=80, width=520, height=340)
        ctx(img)
    img.save(filename='output.png')

“

You're missing the a after rgb color definition. Just update the Drawing.stroke_color property to rgba(0, 0, 0, 0.5).

with Image(filename='logo:') as img:
    with Drawing() as ctx:
        ctx.fill_color = 'transparent'
        ctx.stroke_width = 5
        ctx.stroke_color = 'rgba(0, 0, 0, 0.5)'
        ctx.rectangle(left=60, top=80, width=520, height=340)
        ctx(img)
    img.save(filename='output.png')

output.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文