Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

download unsplash images python no api

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
Comment

python download images from unsplash

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)
Comment

PREVIOUS NEXT
Code Example
Python :: how to remove element from list python by index 
Python :: flask form 
Python :: axis labels python 
Python :: return mean of df as dataframe 
Python :: pd.datetimeindex 
Python :: how to decrease size of graph in plt.scatter 
Python :: load png to python 
Python :: python min value index from an array 
Python :: how to get the most common number in python 
Python :: how to drop duplicate columns in pandas that dont have the same name? 
Python :: python sqrt 
Python :: handwritten digits data set 
Python :: python string replace variable 
Python :: how to read json from python 
Python :: python class arbitrary arguments 
Python :: Python how to use __lt__ 
Python :: matplotlib 
Python :: soustraire deux listes python 
Python :: basic python programs 
Python :: python is not clickable at point (434, 682). Other element would receive the click: 
Python :: Python: Extracting XML to DataFrame (Pandas) 
Python :: trim string to max length python 
Python :: django create super user 
Python :: beautifulsoup get img alt 
Python :: keyboard write python 
Python :: dict in dict in python 
Python :: create python package 
Python :: how to sort values by index pandas 
Python :: circular cropping of image in python 
Python :: rearrange columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =