Compare commits
1 Commits
main
...
feature/as
| Author | SHA1 | Date | |
|---|---|---|---|
| ffd13421ca |
BIN
image-converter/src/assets/clear.jpg
Normal file
BIN
image-converter/src/assets/clear.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 931 KiB |
36
image-converter/src/modules/ascii_parser.py
Normal file
36
image-converter/src/modules/ascii_parser.py
Normal 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"])
|
||||
4
image-converter/src/modules/test/test_ascii.py
Normal file
4
image-converter/src/modules/test/test_ascii.py
Normal file
@@ -0,0 +1,4 @@
|
||||
class TestAsciiConvert:
|
||||
def test_pixel_parse(self):
|
||||
print("__testing")
|
||||
assert 1 + 1 == 2
|
||||
Reference in New Issue
Block a user