MCPcopy Create free account
hub / github.com/ElementsProject/elements / print_image

Function print_image

contrib/signet/getcoins.py:50–69  ·  view source on GitHub ↗

Print black-and-white image to terminal in braille unicode characters.

(img, threshold=128)

Source from the content-addressed store, hash-verified

48 return self._grid[pos[1]][pos[0]]
49
50def print_image(img, threshold=128):
51 '''Print black-and-white image to terminal in braille unicode characters.'''
52 x_blocks = (img.size[0] + BW - 1) // BW
53 y_blocks = (img.size[1] + BH - 1) // BH
54
55 for yb in range(y_blocks):
56 line = []
57 for xb in range(x_blocks):
58 ch = BASE
59 for y in range(BH):
60 for x in range(BW):
61 try:
62 val = img.getpixel((xb * BW + x, yb * BH + y))
63 except IndexError:
64 pass
65 else:
66 if val[0] < threshold:
67 ch |= BIT_PER_PIXEL[y][x]
68 line.append(chr(ch))
69 print(''.join(line))
70
71parser = argparse.ArgumentParser(description='Script to get coins from a faucet.', epilog='You may need to start with double-dash (--) when providing bitcoin-cli arguments.')
72parser.add_argument('-c', '--cmd', dest='cmd', default='bitcoin-cli', help='bitcoin-cli command to use')

Callers 1

getcoins.pyFile · 0.85

Calls 3

chrFunction · 0.85
getpixelMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected