Skip to content

Commit a7379c7

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 94a3472 according to the output from Autopep8. Details: None
1 parent 029ccbe commit a7379c7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Image to ASCII Art/app.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
ASCII_CHARS = '@B%8WM#*oahkbdpwmZO0QCJYXzcvnxrjft/\|()1{}[]-_+~<>i!lI;:,"^`\'. '
44

5+
56
def resize_image(image, new_width=100):
67
width, height = image.size
78
ratio = height / width
89
new_height = int(new_width * ratio)
910
resized_image = image.resize((new_width, new_height))
1011
return resized_image
1112

13+
1214
def grayify(image):
1315
return image.convert("L")
1416

17+
1518
def pixels_to_ascii(image):
1619
pixels = image.getdata()
1720
ascii_str = ""
1821
for pixel in pixels:
1922
ascii_str += ASCII_CHARS[pixel // 25]
2023
return ascii_str
2124

25+
2226
def main(image_path, new_width=100):
2327
try:
2428
image = Image.open(image_path)
@@ -29,16 +33,17 @@ def main(image_path, new_width=100):
2933
image = resize_image(image, new_width)
3034
image = grayify(image)
3135
ascii_str = pixels_to_ascii(image)
32-
36+
3337
ascii_width = image.width
34-
38+
3539
ascii_img = ""
3640
for i in range(0, len(ascii_str), ascii_width):
3741
ascii_img += ascii_str[i:i+ascii_width] + "\n"
38-
42+
3943
print(ascii_img)
4044

45+
4146
if __name__ == "__main__":
42-
image_path = "pngwing.com (1).png"
43-
new_width = 100
47+
image_path = "pngwing.com (1).png"
48+
new_width = 100
4449
main(image_path, new_width)

0 commit comments

Comments
 (0)