build/pypng/piprgb
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: http://pypng.googlecode.com/svn/trunk/code/piprgb $
# $Rev: 131 $
# piprgb
#
# Convert input image to RGB or RGBA format.  Output will be colour type
# 2 or 6, and will not have a tRNS chunk.

import png

def rgb(out, inp):
    """Convert to RGB/RGBA."""

    r = png.Reader(file=inp)
    r.preamble()
    if r.alpha or r.trns:
        get = r.asRGBA
    else:
        get = r.asRGB
    pixels,info = get()[2:4]
    w = png.Writer(**info)
    w.write(out, pixels)

def main(argv=None):
    import sys

    if argv is None:
        argv = sys.argv
    if len(argv) > 1:
        f = open(argv[1], 'rb')
    else:
        f = sys.stdin
    return rgb(sys.stdout, f)

if __name__ == '__main__':
    main()