Skip to content
Newer
Older
100755 81 lines (68 sloc) 2.55 KB
895c929 Add initial version of EventRecorder.
Helder Correia authored Feb 21, 2011
1 #!/usr/bin/env python
2
3 """
4 Copyright (c) 2011 Sencha Inc.
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 """
24
25 import os
26 import sys
27
28 try:
29 from PIL import Image, ImageChops, ImageOps
30 except:
31 print 'Error: the Python Imaging Library is required (see http://www.pythonware.com/products/pil/).'
32 sys.exit(1)
33
34 def printUsage():
35 app = os.path.basename(sys.argv[0])
36 print "Usage:", app, "<image_1> <image_2> <output_image>"
37
38 def main():
39 args = sys.argv[1:]
40 numberOfArgs = len(args)
41 if numberOfArgs != 3:
42 print 'Error: exactly 3 arguments required.'
43 printUsage()
44 return 1
45
46 try:
47 image1 = Image.open(args[0])
48 image1.load()
49 except IOError as e:
50 fileName = "'" + args[0] + "'"
51 if len(e.args) == 2:
52 print 'Error:', e.args[1], fileName
53 return 2
54 print 'Error:', e, fileName
55 return 3
56
57 try:
58 image2 = Image.open(args[1])
59 image2.load()
60 except IOError as e:
61 fileName = "'" + args[1] + "'"
62 if len(e.args) == 2:
63 print 'Error:', e.args[1], fileName
64 return 2
65 print 'Error:', e, fileName
66 return 3
67
68 difference = ImageChops.difference(image1, image2)
69 if difference.getbbox() is None:
70 return 0;
71 difference = difference.convert('RGB')
72 difference = ImageOps.grayscale(difference)
73 difference = ImageOps.invert(difference)
74 try:
75 difference.save(args[2], optimize='1')
76 except KeyError:
77 print 'Error: a valid output image file extension must be provided'
78
79 if __name__ == "__main__":
80 sys.exit(main())
Something went wrong with that request. Please try again.