~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Scripts/explode.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# split an animation into a number of frame files
6
6
#
7
7
 
 
8
from __future__ import print_function
 
9
 
8
10
from PIL import Image
9
 
import os, string, sys
 
11
import os, sys
10
12
 
11
13
class Interval:
12
14
 
18
20
 
19
21
        self.hilo = []
20
22
 
21
 
        for s in string.split(interval, ","):
22
 
            if not string.strip(s):
 
23
        for s in interval.split(","):
 
24
            if not s.strip():
23
25
                continue
24
26
            try:
25
 
                v = string.atoi(s)
 
27
                v = int(s)
26
28
                if v < 0:
27
29
                    lo, hi = 0, -v
28
30
                else:
29
31
                    lo = hi = v
30
32
            except ValueError:
31
 
                i = string.find(s, "-")
32
 
                lo, hi = string.atoi(s[:i]), string.atoi(s[i+1:])
 
33
                i = s.find("-")
 
34
                lo, hi = int(s[:i]), int(s[i+1:])
33
35
 
34
36
            self.hilo.append((hi, lo))
35
37
 
36
38
        if not self.hilo:
37
 
            self.hilo = [(sys.maxint, 0)]
 
39
            self.hilo = [(sys.maxsize, 0)]
38
40
 
39
41
    def __getitem__(self, index):
40
42
 
53
55
    del sys.argv[1]
54
56
 
55
57
if not sys.argv[2:]:
56
 
    print
57
 
    print "Syntax: python explode.py infile template [range]"
58
 
    print
59
 
    print "The template argument is used to construct the names of the"
60
 
    print "individual frame files.  The frames are numbered file001.ext,"
61
 
    print "file002.ext, etc.  You can insert %d to control the placement"
62
 
    print "and syntax of the frame number."
63
 
    print
64
 
    print "The optional range argument specifies which frames to extract."
65
 
    print "You can give one or more ranges like 1-10, 5, -15 etc.  If"
66
 
    print "omitted, all frames are extracted."
 
58
    print()
 
59
    print("Syntax: python explode.py infile template [range]")
 
60
    print()
 
61
    print("The template argument is used to construct the names of the")
 
62
    print("individual frame files.  The frames are numbered file001.ext,")
 
63
    print("file002.ext, etc.  You can insert %d to control the placement")
 
64
    print("and syntax of the frame number.")
 
65
    print()
 
66
    print("The optional range argument specifies which frames to extract.")
 
67
    print("You can give one or more ranges like 1-10, 5, -15 etc.  If")
 
68
    print("omitted, all frames are extracted.")
67
69
    sys.exit(1)
68
70
 
69
71
infile = sys.argv[1]
70
72
outfile = sys.argv[2]
71
73
 
72
 
frames = Interval(string.join(sys.argv[3:], ","))
 
74
frames = Interval(",".join(sys.argv[3:]))
73
75
 
74
76
try:
75
77
    # check if outfile contains a placeholder
87
89
    html = open(file+".html", "w")
88
90
    html.write("<html>\n<body>\n")
89
91
 
90
 
while 1:
 
92
while True:
91
93
 
92
94
    if frames[ix]:
93
95
        im.save(outfile % ix)
94
 
        print outfile % ix
 
96
        print(outfile % ix)
95
97
 
96
98
        if html:
97
99
            html.write("<img src='%s'><br>\n" % outfile % ix)