4
# This python helper script does blend 2 images together and produces
5
# a by KSplashX usuable PNG animation file.
8
# blend.py img1.png img2.png output.png
11
import sys, os, getopt, Image, ImageFile
13
def generate(srcfile1,srcfile2,destfile):
14
srcimg1 = Image.open(srcfile1)
15
srcimg2 = Image.open(srcfile2)
17
(width1,height1) = srcimg1.size
18
(width2,height2) = srcimg2.size
20
maxwidth = width1>width2 and width1 or width2
21
maxheight = height1>height2 and height1 or height2
23
if width1 != maxwidth or height1 != maxheight:
24
srcimg1.resize( (maxwidth,maxheight) )
25
if width2 != maxwidth or height2 != maxheight:
26
srcimg2.resize( (maxwidth,maxheight) )
28
destimg = Image.new( "RGBA", (maxwidth*10,maxheight*2) )
29
for row in range(1,3):
30
for col in range(1,11):
34
alpha = 1.0 - (col*row/20.0)
35
img = Image.blend(srcimg1, srcimg2, alpha)
36
x = maxwidth * col - maxwidth
37
y = maxheight * row - maxheight
38
destimg.paste(img,(x,y))
39
destimg.save(destfile)
43
print "Syntax: %s <inputimagefile1> <inputimagefile2> <outputimagefile>" % os.path.basename(argv[0])
46
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help"])
47
except getopt.GetoptError, err:
48
print str(err) # will print something like "option -a not recognized"
53
if o in ("-h", "--help"):
57
assert False, "unhandled option"
63
generate(args[0],args[1],args[2])
65
if __name__ == "__main__":