mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Add files via upload
This commit is contained in:
parent
1e3c77bb4c
commit
6b21ae7e6e
51
scripts/ImageToAscii/README.md
Normal file
51
scripts/ImageToAscii/README.md
Normal 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%$$
|
||||||
|
$$$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$$
|
||||||
|
%@$$$$$$$$$$$BaZCUYYYYYULqM$$$$$$$$$$$@
|
||||||
|
B%$$$$$$$$$$$$$$%&#**#M8B$$$$$$$$$$$$$%
|
||||||
|
%B%@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@%B
|
43
scripts/ImageToAscii/imgtoascii.py
Normal file
43
scripts/ImageToAscii/imgtoascii.py
Normal 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
BIN
scripts/ImageToAscii/py.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Loading…
Reference in New Issue
Block a user