aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'interlace-frames.py')
-rw-r--r--interlace-frames.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/interlace-frames.py b/interlace-frames.py
new file mode 100644
index 00000000..243e565e
--- /dev/null
+++ b/interlace-frames.py
@@ -0,0 +1,53 @@
1# Copyright (C) 2014 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Script to take a set of frames (PNG files) for a recovery animation
16and turn it into a single output image which contains the input frames
17interlaced by row. Run with the names of all the input frames on the
18command line, in order, followed by the name of the output file."""
19
20import sys
21try:
22 import Image
23 import PngImagePlugin
24except ImportError:
25 print "This script requires the Python Imaging Library to be installed."
26 sys.exit(1)
27
28frames = [Image.open(fn).convert("RGB") for fn in sys.argv[1:-1]]
29assert len(frames) > 0, "Must have at least one input frame."
30sizes = set()
31for fr in frames:
32 sizes.add(fr.size)
33
34assert len(sizes) == 1, "All input images must have the same size."
35w, h = sizes.pop()
36N = len(frames)
37
38out = Image.new("RGB", (w, h*N))
39for j in range(h):
40 for i in range(w):
41 for fn, f in enumerate(frames):
42 out.putpixel((i, j*N+fn), f.getpixel((i, j)))
43
44# When loading this image, the graphics library expects to find a text
45# chunk that specifies how many frames this animation represents. If
46# you post-process the output of this script with some kind of
47# optimizer tool (eg pngcrush or zopflipng) make sure that your
48# optimizer preserves this text chunk.
49
50meta = PngImagePlugin.PngInfo()
51meta.add_text("Frames", str(N))
52
53out.save(sys.argv[-1], pnginfo=meta)