2016-05-08 12 views
0

Ich habe mir ein paar Tage lang den Kopf darüber gekratzt, wie man mit einem Python-Zauberstab die Kanten eines Bildes aus der Picamera verrundet. Ich habe es Setup jetzt, wo es um das Bild packt und Composites es über das Banner/Hintergrundbild mit dem folgenden:Zauberstab Abgerundete Kanten auf Bildern

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

Jede Hilfe ist willkommen!

Antwort

3

Sie können wand.drawing.Drawing.rectangle verwenden, um abgerundete Ecken zu erzeugen und diese mit zusammengesetzten Kanälen zu überlagern.

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

Nun, wenn ich verstehe Ihre Frage, können Sie die gleiche Technik, aber Composite Picture in der Zeichnung Kontext anwenden.

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

+0

gut beantwortet. Upvoted Sie !! –