见代码:
import sys,os
from PIL import Image
if __name__=='__main__':
argc = len(sys.argv)
if argc<3:
print 'usage:%s <file> <dest>'%sys.argv[0]
sys.exit(-1)
im = Image.open(sys.argv[1]).convert('RGBA')
arr = []
(w,h) = im.size
x = 0
y = 0
index = 0
arr_row = []
for pixel in im.getdata():
pixel = list(pixel)
x = index % w
y = index / w
index += 1
pixel[3] = int(256.0*0.2*(float(y)/float(h)))
arr_row.append(tuple(pixel))
if index%w==0 and index>0:
arr = arr_row + arr
arr_row = []
#
im1 = Image.new('RGBA', (w,h))
im1.putdata(arr)
im1.save(sys.argv[2])
原图和效果见下面:
没有评论:
发表评论