Skip to content

Instantly share code, notes, and snippets.

@kirillsulim
Created March 16, 2015 13:05
Show Gist options
  • Save kirillsulim/40802240177aa7aad41a to your computer and use it in GitHub Desktop.
Save kirillsulim/40802240177aa7aad41a to your computer and use it in GitHub Desktop.
from PIL import Image, ImageFilter, ImageDraw
import random
img = Image.open("1.jpg")
width = img.size[0]
height = img.size[1]
mask = Image.new('L', img.size, 255)
maskd = ImageDraw.Draw(mask)
border_thick = 50
sigma = 15
for i in range(0, border_thick):
alpha = random.gauss(i * 255 / border_thick, sigma)
maskd.line([i, i, width - i, i], alpha ) #up
maskd.line([i, height - i, width - i, height - i], alpha) #down
maskd.line([i, i, i, height - i], alpha) #left
maskd.line([width - i, i, width - i, height - i], alpha) #right
mask = mask.filter(ImageFilter.GaussianBlur(3))
img.putalpha(mask)
img.save("1.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment