downloading images from flickr using python-flickr
source link: https://gist.github.com/yunjey/14e3a069ad2aa3adf72dee93a53117d6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
thanks for the code! I'm quite new to python and if I run the script I only get the first url downloaded. Is there a way to download all images from alle the urls? Like an array or loop?
Also, can you specify if its possible to change the path where images are downloaded?
Thanks a lot!
I think it woud work for you
pip install flickrapi
import flickrapi
import urllib
from PIL import Image
from tqdm import tqdm
Flickr api access key
Flickr = flickrapi.FlickrAPI('c6a2c45591d4973ff525042472446ca2', '202ffe6f387ce29b', cache=True)
N_MAX = 60000
KEYWORD = 'cat'
PHOTOs = flickr.walk(text=KEYWORD,
tag_mode='all',
tags=KEYWORD
extras='url_c',
per_page=100, # may be you can try different numbers..
sort='relevance')
URLs = []
for N, PHOTO in tqdm(enumerate(PHOTOs)):
URL = PHOTO.get('url_c')
URLs.append(URL)
# get N_MAX URLs
if N > N_MAX:
break
Download image from the url and save it
RESIZE_OPTION = Image.ANTIALIAS #Image.NEAREST, Image.BICUBIC
for i in range(N_MAX):
fname = f'img_{keyword}{i}.jpg'
urllib.request.urlretrieve(urls[i], f'img{keyword}_{i}.jpg')
# Resize the image and overwrite it
image = Image.open(fname)
image = image.resize((256, 256), RESIZE_OPTION)
image.save(fname)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK