This commit is contained in:
oriol filter 2022-11-26 22:21:39 +00:00
parent b1f24b17ad
commit eb388826ac
2 changed files with 25 additions and 17 deletions

BIN
a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

42
main.py
View File

@ -9,7 +9,12 @@ import numpy as np
import PIL
from dataclasses import dataclass
img = './b.png'
img = './a.png'
character = '#'
size = (170, 200)
# size=(4,4)
# size=(1,1)
scale = 1
windows: bool = True
@ -61,7 +66,7 @@ if windows:
# text=f'{Fore.RED}TEst{Fore.RESET}'
# pyperclip.copy(text)
# text=f"redred"
# text=f"redred"
# text2=f"{Fore.RED}red{Fore.RESET}red"
# text3=f"{Fore.RED}red{Fore.RESET}red".encode().replace(b'\x1b[',b'\x1b[2;').decode()
# print(text)
@ -95,7 +100,7 @@ if windows:
img_data = PIL.Image.open(img)
# print(img_data.info)
img_data = img_data.resize((2, 2), Resampling.NEAREST)
img_data = img_data.resize(size, Resampling.NEAREST)
img_arr = np.array(img_data)
h, w = img_data.size
print(h)
@ -124,35 +129,38 @@ for n, pxl_line in enumerate(img_arr):
# rgb_map[n] = []
rgb_map_line = rgb_map[n]
for pxl in pxl_line:
print(pxl)
r, g, b, _ = pxl
print(r, g, b)
# print(pxl)
r, g, b = pxl[:3]
# print(r, g, b)
_rgb = RGB(red=r, green=g, blue=b)
print(f'>> {_rgb.__str__()}')
rgb_map_line.append(_rgb)
# rgb_map_line.append('')
# print(f'>> {_rgb.__str__()}')
# rgb_map_line.append('')
txt = ""
character = '#'
txt += """```ansi\n"""
for line in rgb_map:
for rgb in line:
rgb: RGB
# print(rgb)
# txt += rgb.__hex__()
txt += rgb
ansi = fg(f'#{rgb.__hex__()}')
# print(f'>> {rgb.__str__()}')
txt += ansi
txt += '#'
txt += '\n'
txt += '\n'
txt += attr('reset')
txt += """```"""
print(txt)
pyperclip.copy(txt)
# print(txt.encode())
# pyperclip.copy(txt)
# x = """
# TEXT
# FF
# TEXT
# FF
# """
# print(x.encode())