Skip to content

Instantly share code, notes, and snippets.

@tajpure
Last active July 29, 2016 02:14
Show Gist options
  • Save tajpure/7fbbdb15e18d1fa28f9d53cc72d2cd4c to your computer and use it in GitHub Desktop.
Save tajpure/7fbbdb15e18d1fa28f9d53cc72d2cd4c to your computer and use it in GitHub Desktop.
#! /bin/python
import os, math
import Image
import ImageDraw
def cut_circle(source, target):
image = Image.open(source).convert("RGBA")
size = image.size
r2 = min(size[0], size[1])
if size[0] != size[1]:
image = image.resize((r2, r2), Image.ANTIALIAS)
circle = Image.new('L', (r2, r2), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, r2, r2), fill=255)
alpha = Image.new('L', (r2, r2), 255)
alpha.paste(circle, (0, 0))
image.putalpha(alpha)
image.save(target)
if __name__ == "__main__":
cut_circle("origin-logo.png", "logo.png")
print("cut finished.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment