Skip to content

Commit 123bf19

Browse files
authored
Merge pull request #641 from FireHead90544/main
Added Image Downloader
2 parents 079177f + 849556d commit 123bf19

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

image_downloader/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Image Downloader
2+
A simple python script to download images by providing link to the images.
3+
4+
## Modules Used
5+
6+
- requests
7+
- pillow
8+
- io
9+
- os
10+
11+
## Requirements
12+
13+
- Run the following in the directory containing the script files.
14+
15+
```bash
16+
pip install requests pillow
17+
```
18+
19+
- Then run the below command
20+
21+
```bash
22+
python image_downloader.py
23+
```

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

image_downloader/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pillow
2+
requests

0 commit comments

Comments
 (0)