Reputation: 114
I have a .txt file with n urls like below:
url1
url2
url3
url4
url5
Upvotes: 0
Views: 23
Reputation: 1526
Here is a rough code with the things needed to achieve your goal:
import requests
from PIL import Image
with open('D:/urls.txt') as f:
urls = f.read().split('\n')
for url in urls:
content = requests.get(url).content
with open('D:/image_big_' + f'{urls.index(url)}' + '.jpg', 'wb') as f:
f.write(content)
with Image.open('D:/image_big_' + f'{urls.index(url)}' + '.jpg') as img:
img.thumbnail(size=(256, 256))
img.save('D:/image_small_' + f'{urls.index(url)}' + '.jpg', bitmap_format="png")
Upvotes: 1