Wand Rounded Edges on Images
Question: I've been scratching my head for a few days on how to complete the task of
making the edges rounded on an image taken from picamera using python-wand. I
have it setup now to where it grabs the image and composites it over the
banner/background image with the following:

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

Any help is appreciated!


Answer: You can use [`wand.drawing.Drawing.rectangle`](http://docs.wand-
py.org/en/0.4.2/wand/drawing.html#wand.drawing.Drawing.rectangle) to generate
rounded corners, and overlay it with composite channels.

    
    
    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](http://i.stack.imgur.com/ikaSR.png)](http://i.stack.imgur.com/ikaSR.png)

Now if I understand your question, you can apply the same technique, but
composite `Picture` in the drawing context.

    
    
    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](http://i.stack.imgur.com/KiimT.png)](http://i.stack.imgur.com/KiimT.png)

