~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksplash/ksplashx/utils/blend.py

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
#
 
4
# This python helper script does blend 2 images together and produces
 
5
# a by KSplashX usuable PNG animation file.
 
6
#
 
7
# Use:
 
8
# blend.py img1.png img2.png output.png
 
9
#
 
10
 
 
11
import sys, os, getopt, Image, ImageFile
 
12
 
 
13
def generate(srcfile1,srcfile2,destfile):
 
14
    srcimg1 = Image.open(srcfile1)
 
15
    srcimg2 = Image.open(srcfile2)
 
16
 
 
17
    (width1,height1) = srcimg1.size
 
18
    (width2,height2) = srcimg2.size
 
19
 
 
20
    maxwidth = width1>width2 and width1 or width2
 
21
    maxheight = height1>height2 and height1 or height2
 
22
 
 
23
    if width1 != maxwidth or height1 != maxheight:
 
24
        srcimg1.resize( (maxwidth,maxheight) )
 
25
    if width2 != maxwidth or height2 != maxheight:
 
26
        srcimg2.resize( (maxwidth,maxheight) )
 
27
 
 
28
    destimg = Image.new( "RGBA", (maxwidth*10,maxheight*2) )
 
29
    for row in range(1,3):
 
30
        for col in range(1,11):
 
31
            if row==1:
 
32
                alpha = col*row/10.0
 
33
            else:
 
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)
 
40
 
 
41
def main(argv):
 
42
    def usage():
 
43
        print "Syntax: %s <inputimagefile1> <inputimagefile2> <outputimagefile>" % os.path.basename(argv[0])
 
44
 
 
45
    try:
 
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"
 
49
        usage()
 
50
        sys.exit(1)
 
51
 
 
52
    for o, a in opts:
 
53
        if o in ("-h", "--help"):
 
54
            usage()
 
55
            sys.exit()
 
56
        else:
 
57
            assert False, "unhandled option"
 
58
 
 
59
    if len(args) < 3:
 
60
        usage()
 
61
        sys.exit(2)
 
62
 
 
63
    generate(args[0],args[1],args[2])
 
64
 
 
65
if __name__ == "__main__":
 
66
    main(sys.argv)