From ea1383b7631951c6148f5f504a3494917a45f97e Mon Sep 17 00:00:00 2001 From: Bhavya Pratap Singh Tomar <66749243+Ankur2606@users.noreply.github.com> Date: Fri, 14 Apr 2023 17:11:22 +0530 Subject: [PATCH] Fixed error with ascii_convert.py and added a feature Fixed the error a lot many of your viewers were facing lately while designating the correct path to the image i.e 'path' is not a valid pathname to an image. Also added a feature such that txt file will be saved with original filename.txt. --- ascii/ascii_convert.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ascii/ascii_convert.py b/ascii/ascii_convert.py index ffdf0161..34e1f717 100644 --- a/ascii/ascii_convert.py +++ b/ascii/ascii_convert.py @@ -1,4 +1,4 @@ -import PIL +from PIL import Image # ascii characters used to build the output text ASCII_CHARS = ["@", "#", "S", "%", "?", "*", "+", ";", ":", ",", "."] @@ -26,7 +26,7 @@ def main(new_width=100): # attempt to open image from user-input path = input("Enter a valid pathname to an image:\n") try: - image = PIL.Image.open(path) + image = Image.open(path) except: print(path, " is not a valid pathname to an image.") return @@ -42,7 +42,7 @@ def main(new_width=100): print(ascii_image) # save result to "ascii_image.txt" - with open("ascii_image.txt", "w") as f: + with open(f"{path[:-4]}.txt", "w") as f: f.write(ascii_image) # run program