Image compilation

I have the name of the album of some kind of musical group. I want to draw it with a mask that will be around the corners of the image. So, I prepared such a mask in gimp:

enter image description here

I use a white mask, but here it is invisible on a white background. So here is the rendering code:

# Draw album image img = cairo.ImageSurface.create_from_png('images/album.png') ctx.set_source_surface(img, posX, posY) ctx.paint() # Draw mask ctx.set_operator(cairo.OPERATOR_DEST_IN) img = cairo.ImageSurface.create_from_png('images/mask.png') ctx.set_source_surface(img, posX, posY) ctx.paint() 

As you can see, I used OPERATOR_DEST_IN . Brief examples I have found in this page .

But everything disappeared in my program when I installed the layout operator in cairo :( When I comment on this line, everything is fine, but the mask is above my image. What is the right way for this?

ps I am using python2, cairo library


When I delete the layout operator, I see (do not forget that the real mask is white, in this case the album image is dark):

enter image description here

+6
python image composite cairo
source share
1 answer

You also need to share your surface creation code, here is some code that I expanded from your example:

 import cairo surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, 128, 128) ctx = cairo.Context (surface) posX = posY = 0 img = cairo.ImageSurface.create_from_png('sample.png') ctx.set_source_surface(img, posX, posY) ctx.paint() # Draw mask ctx.set_operator(cairo.OPERATOR_DEST_IN) img = cairo.ImageSurface.create_from_png('mask.png') ctx.set_source_surface(img, posX, posY) ctx.paint() surface.write_to_png ("example.png") # Output to PNG 

Generated this beautiful png below (it was the only image on my desktop at the moment;) enter image description here

+7
source share

All Articles