魔杖圆形边缘图像

时间:2016-05-08 01:49:37

标签: python-2.7 raspbian wand

我已经摸了几天关于如何完成使用python-wand从picamera拍摄的图像边缘四舍五入的任务。我现在将它设置为抓取图像的位置,并使用以下内容将其合成在横幅/背景图像上:

img = Image(filename=Picture)                                         
img.resize(1200, 800)
bimg = Image(filename=Background)
bimg.composite(img, left=300, top=200)
bimg.save(filename=BPicture)

感谢任何帮助!

1 个答案:

答案 0 :(得分:5)

您可以使用wand.drawing.Drawing.rectangle生成圆角,并使用复合频道覆盖它。

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

with Image(filename='rose:') as img:
    img.resize(240, 160)
    with Image(width=img.width,
               height=img.height,
               background=Color("white")) as mask:

        with Drawing() as ctx:
            ctx.fill_color = Color("black")
            ctx.rectangle(left=0,
                          top=0,
                          width=mask.width,
                          height=mask.height,
                          radius=mask.width*0.1)  # 10% rounding?
            ctx(mask)
        img.composite_channel('all_channels', mask, 'screen')
        img.save(filename='/tmp/out.png')

Wand rounded edges

现在,如果我理解了您的问题,您可以应用相同的技术,但在绘图环境中复合Picture

with Image(filename='rose:') as img:
    img.resize(240, 160)
    with Image(img) as nimg:
        nimg.negate()  # For fun, let's negate the image for the background
        with Drawing() as ctx:
            ctx.fill_color = Color("black")
            ctx.rectangle(left=0,
                          top=0,
                          width=nimg.width,
                          height=nimg.height,
                          radius=nimg.width*0.3)  # 30% rounding?
            ctx.composite('screen', 0, 0, nimg.width, nimg.height, img)
            ctx(nimg)
        nimg.save(filename='/tmp/out2.png')

Wand rounded edges with background