summaryrefslogtreecommitdiffstats
path: root/build/pypng/pnglsch
blob: d10d23809f866f96153583f78a73908625114e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# $URL: http://pypng.googlecode.com/svn/trunk/code/pnglsch $
# $Rev: 107 $
# pnglsch
# PNG List Chunks

import png

def list(out, inp):
    r = png.Reader(file=inp)
    for t,v in r.chunks():
        add = ''
        if len(v) <= 28:
            add = ' ' + v.encode('hex')
        print >>out, "%s %10d%s" % (t, len(v), add)

def main(argv=None):
    import sys

    if argv is None:
        argv = sys.argv
    arg = argv[1:]

    if len(arg) > 0:
        f = open(arg[0], 'rb')
    else:
        f = sys.stdin
    return list(sys.stdout, f)

if __name__ == '__main__':
    main()