pnglsch 605 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. # $URL: http://pypng.googlecode.com/svn/trunk/code/pnglsch $
  3. # $Rev: 107 $
  4. # pnglsch
  5. # PNG List Chunks
  6. import png
  7. def list(out, inp):
  8. r = png.Reader(file=inp)
  9. for t,v in r.chunks():
  10. add = ''
  11. if len(v) <= 28:
  12. add = ' ' + v.encode('hex')
  13. print >>out, "%s %10d%s" % (t, len(v), add)
  14. def main(argv=None):
  15. import sys
  16. if argv is None:
  17. argv = sys.argv
  18. arg = argv[1:]
  19. if len(arg) > 0:
  20. f = open(arg[0], 'rb')
  21. else:
  22. f = sys.stdin
  23. return list(sys.stdout, f)
  24. if __name__ == '__main__':
  25. main()