diff --git a/README.md b/README.md index 0dc88d4..dfd7569 100644 --- a/README.md +++ b/README.md @@ -332,4 +332,4 @@ Thanks a lot for spending your time helping! Keep rocking 🍻 - \ No newline at end of file + diff --git a/scripts/ImageToAscii/README.md b/scripts/ImageToAscii/README.md new file mode 100644 index 0000000..b46f22b --- /dev/null +++ b/scripts/ImageToAscii/README.md @@ -0,0 +1,51 @@ +# Image to ASCII Art +This is a simple script that lets you convert an image to ascii text art. + +## Usage + +* Only PIL package is required +* Add path of your picture and set size of width and height by pixel. +* Run `python imgtoascii.py` +* Enjoy ASCII art! + +## Result : + +B%B%B@@$$$$$$$$$$$$$$$$$$$$$$$$$$@@B%B% +%B%@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@%B +B%$$$$$$$$$$$$$$&obpdk*8$$$$$$$$$$$$$$% +%@$$$$$$$$$$$#X)_i!ll!i?\Q%$$$$$$$$$$$@ +B$$$$$$$$$$$m_;Il!!!!!!lll{h$$$$$$$$$$$ +@$$$$$$$$$$#+ltU[l!!!!!!!!l[&$$$$$$$$$$ +@$$$$$$$$$$wI[@$pl!!!!!!!!!IO$$$$$$$$$$ +$$$$$$$$$$$wI]8$ml!!!!!!!!!lJ$$$$$$$$$$ +$$$$$$$$$$$wll)x_!!!!!!!!!!lC$$$$$$$$$$ +$$$$$$$$$$$wIlI;Illl!!!!!!!lC$$$$$$$$$$ +$$$$$$$$$$$#zXXXXXXz_!!!!!!lC$$$$$$$$$$ +$$$$$$8bqpppbbbbbbbd?l!!!!!lC&bbboB$$$$ +$$$$$C?lllllllllllll!!!!!!!lLoYYYYQW$$$ +$$$$Yll!!!!!!!!!!!!!!!!!!!!lLoYUUUYQ%$$ +$$$ail!!!!!!!!!!!!!!!!!!!!!lLoYUUUUYb$$ +$$$nI!!!!!!!!!!!!!!!!!!!!!!l0oYUUUUYQ@$ +$$B}l!!!!!!!!!!!!!!!!!!!!!!lkhYUUUUUU&$ +$$#~!!!!!!!!!!!!!!!!!!!!!!I\@mYUUUUUY*$ +$$k!!!!!!!!!!lllllllllllI!\WWUUUUUUUYo$ +$$dl!!!!!!!!l1uXYYYYYYYYCh@WLYUUUUUUYo$ +$$dl!!!!!!!~0@%*aaaaaaaaakmUYUUUUUUUYo$ +$$k!!!!!!!lL@dJYYYYYYYYYYYYUUUUUUUUUYo$ +$$*~!!!!!l]BdYYUUUUUUUUUUUUUUUUUUUUUY*$ +$$%]l!!!!lfBJYUUUUUUUUUUUUUUUUUUUUUUU&$ +$$$tl!!!!luWYUUUUUUUUUUUUUUUUUUUUUUY0@$ +$$$wl!!!!luMYUUUUUUUUUUUUUUUUUUUUUUYa$$ +$$$B\I!!!luMYUUUUUUUUUUUUUUUUUUUUUYZ@$$ +$$$$M)Ill;nMYUUUUUUUYYYYYYYYYYYYYJqB$$$ +$$$$$%OunxZMYUUUUUUUa********ooo*&$$$$$ +$$$$$$$$$$$#YUUUUUUUbhhhhhhhW$$$$$$$$$$ +$$$$$$$$$$$#YUUUUUUUYYYYYYYYb$$$$$$$$$$ +$$$$$$$$$$$#YUUUUUUUUUUUmOYYb$$$$$$$$$$ +$$$$$$$$$$$#YUUUUUUUUUYd$@OYb$$$$$$$$$$ +@$$$$$$$$$$MYUUUUUUUUUYh$$mYb$$$$$$$$$$ +@$$$$$$$$$$@0YUUUUUUUUYChdUY*$$$$$$$$$$ +B$$$$$$$$$$$&0YYYUUUUUUYYYUd@$$$$$$$$$$ +%@$$$$$$$$$$$BaZCUYYYYYULqM$$$$$$$$$$$@ +B%$$$$$$$$$$$$$$%&#**#M8B$$$$$$$$$$$$$% +%B%@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@%B diff --git a/scripts/ImageToAscii/imgtoascii.py b/scripts/ImageToAscii/imgtoascii.py new file mode 100644 index 0000000..dc0e39a --- /dev/null +++ b/scripts/ImageToAscii/imgtoascii.py @@ -0,0 +1,43 @@ +from PIL import Image + +ascii_characters_by_surface = r'`^\",:;Il!i~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$' + +def convert_to_ascii_art(image): + ascii_art = [] + (width, height) = image.size + for y in range(0, height - 1): + line = '' + for x in range(0, width - 1): + px = image.getpixel((x, y)) + line += convert_pixel_to_character(px) + ascii_art.append(line) + return ascii_art + + +def convert_pixel_to_character(pixel): + (r, g, b) = pixel + pixel_brightness = r + g + b + max_brightness = 255 * 3 + brightness_weight = len(ascii_characters_by_surface) / max_brightness + index = int(pixel_brightness * brightness_weight) - 1 + return ascii_characters_by_surface[index] + + +def save_as_text(ascii_art): + with open("image.txt", "w") as file: + for line in ascii_art: + file.write(line) + file.write('\n') + file.close() + +def main(): + imdir = input('Please add your image direction carefully: ') + imsize = input('Please set a value for width and height: ') + image = Image.open(imdir) + image = image.resize((int(imsize), int(imsize))) + ascii_art = convert_to_ascii_art(image) + save_as_text(ascii_art) + print("Your ascii art is printed on image.txt file!") + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ImageToAscii/py.jpg b/scripts/ImageToAscii/py.jpg new file mode 100644 index 0000000..efca7d7 Binary files /dev/null and b/scripts/ImageToAscii/py.jpg differ