Add files via upload

This commit is contained in:
tolgakurtuluss 2022-10-05 14:20:12 +03:00 committed by GitHub
parent 1e3c77bb4c
commit 6b21ae7e6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 0 deletions

View File

@ -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

View File

@ -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()

BIN
scripts/ImageToAscii/py.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB