from typing import Tuple import PIL.Image from PIL.Image import Resampling from colorama import Fore, Back, Style from colored import fg, bg, attr import pyperclip import numpy as np import PIL from dataclasses import dataclass img = './a.png' character = '#' size = (170, 200) # size=(4,4) # size=(1,1) scale = 1 windows: bool = True class RGB: _red: int = 0 _green: int = 0 _blue: int = 0 def __init__(self, red=0, green=0, blue=0): self.red = red self.green = green self.blue = blue def __hex__(self): return f"{'%02x' % self.red}{'%02x' % self.green}{'%02x' % self.blue}".upper() def __str__(self) -> tuple[int, int, int]: return self.red, self.green, self.blue @property def red(self): return self._red @red.setter def red(self, x): self._red = int(x) @property def green(self): return self._green @green.setter def green(self, x): self._green = int(x) @property def blue(self): return self._blue @blue.setter def blue(self, x): self._blue = int(x) def rr(char: str, color: RGB): return f"\033[38;2;{color.red};{color.green};{color.red}m{char} \033[38;2;255;255;255m" if windows: from colorama import just_fix_windows_console just_fix_windows_console() # # text=f'{Fore.RED}TEst{Fore.RESET}' # pyperclip.copy(text) # 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) # print(text2) # print(text3) # print(text2.encode()) # print(text.encode()) # print(text3.encode()) # print(Back.GREEN + 'and with a green background') # print(Style.DIM + 'and in dim text') # print(Style.RESET_ALL) # print('back to normal now') # # text=f'{Fore.RED}TEst{Fore.RESET}' # pyperclip.copy(text) # 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) # print(text2) # print(text3) # print(text2.encode()) # print(text.encode()) # print(text3.encode()) # print(Back.GREEN + 'and with a green background') # print(Style.DIM + 'and in dim text') # print(Style.RESET_ALL) # print('back to normal now') img_data = PIL.Image.open(img) # print(img_data.info) img_data = img_data.resize(size, Resampling.NEAREST) img_arr = np.array(img_data) h, w = img_data.size print(h) print(w) # img_data.save('z.png') # r = RGB() # print(r.__hex__()) # print(img_arr) # color = fg('#C0C0C0') + bg('#00005f') # res = attr('reset') # t = color + "Hello World !!!" + res # print(t) # print(t.encode()) # print(fg('#00FF16').encode()) # print('fuck') # print(f'{fg(1)} Hello World !!! {attr(0)}') # print(bg(30)) # print(res) rgb_map: [[RGB]] = [] for n, pxl_line in enumerate(img_arr): # print(n) rgb_map.append([]) # print(rgb_map[0]) # rgb_map[n] = [] rgb_map_line = rgb_map[n] for pxl in pxl_line: # print(pxl) r, g, b = pxl[:3] # print(r, g, b) _rgb = RGB(red=r, green=g, blue=b) rgb_map_line.append(_rgb) # print(f'>> {_rgb.__str__()}') # rgb_map_line.append('') txt = "" txt += """```ansi\n""" for line in rgb_map: for rgb in line: rgb: RGB # print(rgb) ansi = fg(f'#{rgb.__hex__()}') # print(f'>> {rgb.__str__()}') txt += ansi txt += '#' txt += '\n' txt += attr('reset') txt += """```""" print(txt) # print(txt.encode()) # pyperclip.copy(txt) # x = """ # TEXT # FF # """ # print(x.encode())