Skip to content

Commit d33a400

Browse files
Image Downloader | Issue #631
1 parent d081e05 commit d33a400

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

image_downloader/main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
from PIL import Image
3+
from io import BytesIO
4+
import os
5+
6+
download_path = os.path.dirname(os.path.abspath(__file__))
7+
count = 1
8+
while True:
9+
url = input("Enter Image URL: ")
10+
try:
11+
res = requests.get(url)
12+
except Exception:
13+
print("Invalid URL / Can't Access The URL")
14+
continue
15+
16+
img = Image.open(BytesIO(res.content))
17+
format = img.format
18+
imgLoc = os.path.join(download_path, f"{count}.{format.lower()}")
19+
img = img.save(imgLoc, format=format.upper())
20+
print(f"Image Downloaded: {imgLoc}")
21+
count += 1

0 commit comments

Comments
 (0)