-4 years ago 231
Python Question

How to create a circular image using python pillow and overlap with background image



How to synthesize two images as follows?

I Effect:

Answer Source

Here's an example using your images. Dimensions are hardcoded in the example, but you can easily replace them with calculations. avatar.jpg and background.jpg are images in your post saved as is.

Here's a link to github repo for this example : python_pillow_circular_thumbnail

from PIL import Image, ImageOps, ImageDraw

im ='avatar.jpg')
im = im.resize((120, 120));
bigsize = (im.size[0] * 3, im.size[1] * 3)
mask ='L', bigsize, 0)
draw = ImageDraw.Draw(mask) 
draw.ellipse((0, 0) + bigsize, fill=255)
mask = mask.resize(im.size, Image.ANTIALIAS)

output =, mask.size, centering=(0.5, 0.5))

background ='back.jpg')
background.paste(im, (150, 10), im)'overlap.png')

output.png: enter image description here

overlap.png: enter image description here

Crop part of this code is borrowed form this answer.

Hope it helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download