author tbirdbld
Wed, 24 Sep 2014 00:53:52 -0400
changeset 16126 4b8605e6a17d6bfb0d0dfbe92049ea3be7aaeeba
parent 8729 923b924c9422bddc54a3d8c08b765da58dddeedd
permissions -rw-r--r--
Automated checkin: version bump for thunderbird 24.8.1 release. DONTBUILD CLOSED TREE a=release

#!/usr/bin/env python
# $URL: $
# $Rev: 77 $

import itertools
import sys

import png

def cat(out, l):
    """Concatenate the list of images.  All input images must be same
    height and have the same number of channels.  They are concatenated
    left-to-right.  `out` is the (open file) destination for the
    output image.  `l` should be a list of open files (the input
    image files).

    l = map(lambda f: png.Reader(file=f), l)
    # Ewgh, side effects.
    map(lambda r: r.preamble(), l)
    # The reference height; from the first image.
    height = l[0].height
    # The total target width
    width = 0
    for i,r in enumerate(l):
        if r.height != height:
            raise Error('Image %d, height %d, does not match %d.' %
              (i, r.height, height))
        width += r.width
    pixel,info = zip(*map(lambda r: r.asDirect()[2:4], l))
    tinfo = dict(info[0])
    del tinfo['size']
    w = png.Writer(width, height, **tinfo)
    def itercat():
        for row in itertools.izip(*pixel):
            yield itertools.chain(*row)
    w.write(out, itercat())

def main(argv):
    return cat(sys.stdout, map(lambda n: open(n, 'rb'), argv[1:]))

if __name__ == '__main__':