import requests
# Download an image off unsplash without the api using python
def downloadimages(search_term, resolution, amount): # Define the function to download images
print(f"https://source.unsplash.com/random/{resolution}/?"+str(search_term)+", allow_redirects=True") # State the URL
for x in range(int(amount)): # Loop for chosen amount of times
response = requests.get(f"https://source.unsplash.com/random/{resolution}/?"+str(search_term)+", allow_redirects=True") # Download the photo(s)
print("Saving to: ./photos/" + str(search_term) + "_" + str(x + 1) + ".png") # State the filename
open("./photos/" + str(search_term) + "_" + str(x + 1) + ".png", 'wb').write(response.content) # Write image file
downloadimages("nature", "1080x1920", 15) # Call the Function
from pyunsplash import PyUnsplash
import requests
from PIL import Image
# Put in your Unsplash API Key
pu = PyUnsplash(api_key="<put your api key here>")
# Request from the api
photos = pu.photos(type_='random', count=1, featured=True, query="splash") # Query the search term
[photo] = photos.entries
print(photo.id, photo.link_download) # Print the photo ID and link
response = requests.get(photo.link_download, allow_redirects=True) # Download the photo
open('./unsplash_temp.png', 'wb').write(response.content) # Write image file
im = Image.open("./unsplash_temp.png") # Open and
im.show() # Show the image (optional)