-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmess.py
More file actions
48 lines (38 loc) · 1.24 KB
/
mess.py
File metadata and controls
48 lines (38 loc) · 1.24 KB
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
import itertools
from typing import Mapping, Tuple
from PIL import Image
from rich.color import Color, ColorType
from rich.color_triplet import ColorTriplet
from rich.console import Console
from rich.segment import Segment, SegmentLines
from rich.style import Style
from rich_img.image import get_cell
Pixel = Tuple[int, int, int]
Coordinate = Tuple[int, int]
PixelAccessor = Mapping[Coordinate, Pixel]
with Image.open("./tests/img/island.jpg") as file:
img_size = file.size
pix: PixelAccessor = file.load() # type: ignore
print(img_size)
to_render = []
for y in range(0, img_size[1]-8, 8):
li = []
for x in range(0, img_size[0]-4, 4):
pixels = [pix[(x, y)]
for y, x in itertools.product(range(y, y+8), range(x, x+4))]
cell = get_cell(pixels)
seg = Segment(
cell.char,
Style(
bgcolor=Color('bg', type=ColorType(3),
triplet=ColorTriplet(*cell.bg_color)),
color=Color("fg", type=ColorType(3),
triplet=ColorTriplet(*cell.fg_color))
)
)
li.append(seg)
to_render.append(li)
rend = SegmentLines(to_render, new_lines=True)
c = Console()
c.print(rend)
c.print('\n')