Skip to content

Instantly share code, notes, and snippets.

@falsetru
Created March 9, 2011 15:09
Show Gist options
  • Save falsetru/862350 to your computer and use it in GitHub Desktop.
Save falsetru/862350 to your computer and use it in GitHub Desktop.
generate fadeout image
import os, sys, Image
# Usage $0 image width-for-new-file
filename = sys.argv[1] #'tv_main_bar_bg.png'
filename2 = '_fadeout'.join(os.path.splitext(filename))
width = int(sys.argv[2])
maxx = width - 1
im = Image.open(filename)
assert im.size[0] == 1
im2 = Image.new('RGBA', (width, im.size[1]))
for y in range(im.size[1]):
r,g,b = im.getpixel((0, y))
for x in range(width):
xx = maxx - x
alpha = 255 - (255 * xx * xx / maxx / maxx)
im2.putpixel((x,y), (r,g,b,alpha))
im2.save(filename2)
import os;os.system('open '+filename2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment