pripnglsch 721 B

123456789101112131415161718192021222324252627282930313233
  1. #!D:\TestPythonProject\TEST\venv\Scripts\python.exe
  2. # pripnglsch
  3. # PNG List Chunks
  4. import png
  5. def list_chunks(out, inp):
  6. r = png.Reader(file=inp)
  7. for t, v in r.chunks():
  8. add = ""
  9. if len(v) <= 28:
  10. add = " " + v.hex()
  11. else:
  12. add = " " + v[:26].hex() + "..."
  13. t = t.decode("ascii")
  14. print("%s %10d%s" % (t, len(v), add), file=out)
  15. def main(argv=None):
  16. import argparse
  17. import sys
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument(
  20. "input", nargs="?", default="-", type=png.cli_open, metavar="PNG"
  21. )
  22. args = parser.parse_args()
  23. return list_chunks(sys.stdout, args.input)
  24. if __name__ == "__main__":
  25. main()