oriol filter b1f24b17ad test
2022-11-26 20:54:36 +00:00

159 lines
3.4 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 = './b.png'
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((2, 2), 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
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('')
txt = ""
character = '#'
txt += """```ansi\n"""
for line in rgb_map:
for rgb in line:
rgb: RGB
# print(rgb)
# txt += rgb.__hex__()
txt += rgb
txt += '#'
txt += '\n'
txt += """```"""
print(txt)
pyperclip.copy(txt)
# x = """
# TEXT
# FF
# """
# print(x.encode())