diff --git a/image-converter/src/assets/clear.jpg b/image-converter/src/assets/clear.jpg new file mode 100644 index 0000000..6a4888d Binary files /dev/null and b/image-converter/src/assets/clear.jpg differ diff --git a/image-converter/src/modules/ascii_parser.py b/image-converter/src/modules/ascii_parser.py new file mode 100644 index 0000000..fbb8916 --- /dev/null +++ b/image-converter/src/modules/ascii_parser.py @@ -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"]) diff --git a/image-converter/src/modules/test/test_ascii.py b/image-converter/src/modules/test/test_ascii.py new file mode 100644 index 0000000..f4c8030 --- /dev/null +++ b/image-converter/src/modules/test/test_ascii.py @@ -0,0 +1,4 @@ +class TestAsciiConvert: + def test_pixel_parse(self): + print("__testing") + assert 1 + 1 == 2