test
This commit is contained in:
parent
52e2aff3cd
commit
b1f24b17ad
130
main.py
130
main.py
@ -1,9 +1,13 @@
|
||||
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
|
||||
@ -11,17 +15,38 @@ windows: bool = True
|
||||
|
||||
|
||||
class RGB:
|
||||
def __init__(self):
|
||||
pass
|
||||
_red: int = 0
|
||||
_green: int = 0
|
||||
_blue: int = 0
|
||||
|
||||
red: int = 0
|
||||
green: int = 255
|
||||
blue: int = 255
|
||||
def __init__(self, red=0, green=0, blue=0):
|
||||
self.red = red
|
||||
self.green = green
|
||||
self.blue = blue
|
||||
|
||||
def __hex__(self):
|
||||
h = f"{'%02x' % self.red}{'%02x' % self.green}{'%02x' % self.blue}".upper()
|
||||
print(h)
|
||||
return h
|
||||
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):
|
||||
@ -50,21 +75,84 @@ if windows:
|
||||
# print(Style.RESET_ALL)
|
||||
# print('back to normal now')
|
||||
|
||||
img_data = PIL.Image.open(img)
|
||||
print(img_data.info)
|
||||
img_arr = np.array(img_data)
|
||||
#
|
||||
for line in img_arr:
|
||||
print(line)
|
||||
# text=f'{Fore.RED}TEst{Fore.RESET}'
|
||||
# pyperclip.copy(text)
|
||||
|
||||
r = RGB()
|
||||
# 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())
|
||||
# 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)
|
||||
|
||||
print(f'{fg(1)} Hello World !!! {attr(0)}')
|
||||
print(bg(30))
|
||||
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('[31m')
|
||||
|
||||
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 += '[39m\n'
|
||||
txt += """```"""
|
||||
print(txt)
|
||||
|
||||
pyperclip.copy(txt)
|
||||
|
||||
# x = """
|
||||
# [31mTEXT
|
||||
# FF[39m
|
||||
# """
|
||||
# print(x.encode())
|
||||
|
Loading…
x
Reference in New Issue
Block a user