gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

82 行
2.0KB

  1. #!C:\odoobuild\WinPy64\python-3.12.3.amd64\python.exe
  2. # http://www.python.org/doc/2.4.4/lib/module-itertools.html
  3. import itertools
  4. import sys
  5. import png
  6. Description = """Join PNG images in a column top-to-bottom."""
  7. class FormatError(Exception):
  8. """
  9. Some problem with the image format.
  10. """
  11. def join_col(out, l):
  12. """
  13. Join the list of images.
  14. All input images must be same width and
  15. have the same number of channels.
  16. They are joined top-to-bottom.
  17. `out` is the (open file) destination for the output image.
  18. `l` should be a list of open files (the input image files).
  19. """
  20. image = 0
  21. stream = 0
  22. # When the first image is read, this will be the reference width,
  23. # which must be the same for all images.
  24. width = None
  25. # Total height (accumulated as images are read).
  26. height = 0
  27. # Accumulated rows.
  28. rows = []
  29. for f in l:
  30. stream += 1
  31. while True:
  32. im = png.Reader(file=f)
  33. try:
  34. im.preamble()
  35. except EOFError:
  36. break
  37. image += 1
  38. if not width:
  39. width = im.width
  40. elif width != im.width:
  41. raise FormatError('Image %d in stream %d has width %d; does not match %d.' %
  42. (image, stream, im.width, width))
  43. height += im.height
  44. # Various bugs here because different numbers of channels and depths go wrong.
  45. w, h, p, info = im.asDirect()
  46. rows.extend(p)
  47. # Alarmingly re-use the last info object.
  48. tinfo = dict(info)
  49. del tinfo['size']
  50. w = png.Writer(width, height, **tinfo)
  51. w.write(out, rows)
  52. def main(argv):
  53. import argparse
  54. parser = argparse.ArgumentParser(description=Description)
  55. parser.add_argument(
  56. "input", nargs="*", default="-", type=png.cli_open, metavar="PNG"
  57. )
  58. args = parser.parse_args()
  59. return join_col(png.binary_stdout(), args.input)
  60. if __name__ == '__main__':
  61. main(sys.argv)
上海开阖软件有限公司 沪ICP备12045867号-1