Skip to content

Instantly share code, notes, and snippets.

@YusukeIwaki
Created September 19, 2016 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YusukeIwaki/8dc8846308beefbb05553f8ef3522e1b to your computer and use it in GitHub Desktop.
Save YusukeIwaki/8dc8846308beefbb05553f8ef3522e1b to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
from PIL import Image
img = Image.open("/Users/yi01/Downloads/icon_終了.png")
img2 = Image.new("LA",img.size)
pix=img.load()
pix2=img2.load()
w,h=img.size
for y in xrange(h):
for x in xrange(w):
r,g,b,a = pix[x,y]
l=r*a/255
pix2[x,y]=(l,l) if l>128 else (0,0)
img2.save("/Users/yi01/Downloads/icon_alpha.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment