Created
November 3, 2020 21:41
-
-
Save ligix/081676b6bfd3671aaae1d98d2f91c84c to your computer and use it in GitHub Desktop.
Ascii art one liner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url="https://i.kym-cdn.com/photos/images/original/000/711/604/f6d.jpg";W=300;H=300;out="art.txt";asc="█@#O$%?o*+;:,. ";import requests;from PIL import Image;from io import BytesIO, StringIO;(a:=StringIO(),i:=Image.open(BytesIO(requests.get(url).content)),i:=i.convert("L"),w:=i.size[0],h:=i.size[1],r:=min(W/w,H/h),i:=i.resize((w:=int(w*r),h:=int(h*r))),[([a.write(asc[i.getpixel((x,y))//(255//len(asc))-1]) for x in range(w)], a.write("\n")) for y in range(h)]),open(out,"w").write(a.getvalue()) # url: url of the photo; W,H: maximum width / hieght of the ascii art; out: file where the ascii art will be saved; asc: characters, from the "darkest" to the "whitest". If you want to run it with python -c use single quotes ' to wrap the code, not double quotes " for obvious reasons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
url:
url of the photo
W,H:
maximum width / hieght of the ascii art
out:
file where the ascii art will be saved
asc:
characters, from the "darkest" to the "whitest"
If you want to run it with python -c use single quotes ' to wrap the code, not double quotes " for obvious reasons