Catalyst / admin/Synapse-Cortex 14.8 GB / 57.8 GB 40.0 GB free
Help Sign in

admin / Synapse-Cortex

public

Self Hosted ITSM Tool with RBAC/Tenanting and MFA

Code Issues Pull requests Pipelines Packages Security Insights Wiki Settings
Synapse-Cortex / synapse-cortex / .venv / Scripts / prirowpng 1984 B · main
 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!C:\Users\hanco\.openclaw\ClaudeLocal\synapse-cortex\.venv\Scripts\python.exe

# http://www.python.org/doc/2.4.4/lib/module-itertools.html
import itertools
import sys

import png

Description = """Join PNG images in a row left-to-right."""


class FormatError(Exception):
    """
    Some problem with the image format.
    """


def join_row(out, l):
    """
    Concatenate the list of images.
    All input images must be same height and
    have the same number of channels.
    They are concatenated left-to-right.
    `out` is the (open file) destination for the output image.
    `l` should be a list of open files (the input image files).
    """

    l = [png.Reader(file=f) for f in l]

    # Ewgh, side effects.
    for r in l:
        r.preamble()

    # The reference height; from the first image.
    height = l[0].height
    # The total target width
    width = 0
    for i,r in enumerate(l):
        if r.height != height:
            raise FormatError('Image %d, height %d, does not match %d.' %
              (i, r.height, height))
        width += r.width

    # Various bugs here because different numbers of channels and depths go wrong.
    pixel, info = zip(*[r.asDirect()[2:4] for r in l])
    tinfo = dict(info[0])
    del tinfo['size']
    w = png.Writer(width, height, **tinfo)

    def iter_all_rows():
        for row in zip(*pixel):
            # `row` is a sequence that has one row from each input image.
            # list() is required here to hasten the lazy row building;
            # not sure if that's a bug in PyPNG or not.
            yield list(itertools.chain(*row))
    w.write(out, iter_all_rows())

def main(argv):
    import argparse

    parser = argparse.ArgumentParser(description=Description)
    parser.add_argument(
        "input", nargs="*", default="-", type=png.cli_open, metavar="PNG"
    )

    args = parser.parse_args()

    return join_row(png.binary_stdout(), args.input)

if __name__ == '__main__':
    main(sys.argv)