Skip to content

Instantly share code, notes, and snippets.

@guyoun
Last active January 8, 2016 02:35
Show Gist options
  • Save guyoun/8e54dd35edc19ebab441 to your computer and use it in GitHub Desktop.
Save guyoun/8e54dd35edc19ebab441 to your computer and use it in GitHub Desktop.
Merge two images using PIL
from PIL import Image
img = Image.new("RGBA", (400,570))
bg = Image.open("./s3.png")
fg = Image.open("./p1.png")
img.paste(bg, (0,0),bg)
img.paste(fg, (0,0),fg)
bg.paste(fg, (0, 0), fg)
img_alpha = Image.alpha_composite(bg,fg)
img.save("./merge.png")
bg.save("./bg-merge.png")
img_alpha.save("./alpha-merge.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment