feat: ascii parser base code

This commit is contained in:
2026-02-13 14:59:25 +01:00
parent cf07ab9d88
commit ffd13421ca
3 changed files with 40 additions and 0 deletions

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 KiB

View File

@@ -0,0 +1,36 @@
from PIL import Image
def convert_ascii(src: str, width: int, weight: int, charset: [str]):
# Open an image file
img = Image.open(src)
gray_scale = len(charset)
print("__char", charset, gray_scale)
img_width, img_height = img.size
px = img.load()
# Use image parser to take resolution down
# Convert to grayscale
# Calc color differences
# Stablish defined character based on the color variance
min_color = 255
max_color = 0
for x in range(img_width):
for y in range(img_height):
# r, g, b = px[x, y]
gray_px = sum(px[x, y]) // 3
px[x,y] = (gray_px, gray_px, gray_px)
if (min_color > gray_px):
min_color = gray_px
elif (max_color < gray_px):
max_color = gray_px
print("Pixels", px[0,0], min_color, max_color) # --> outputs a three-dimensional array, rgb
convert_ascii('src/assets/fee.jpg', 100, 100, ["a", "b", "c"])
convert_ascii('src/assets/clear.jpg', 100, 100, ["a", "b", "c"])

View File

@@ -0,0 +1,4 @@
class TestAsciiConvert:
def test_pixel_parse(self):
print("__testing")
assert 1 + 1 == 2