Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

download unsplash images python

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 :: try catch python with open 
Python :: how ro have a incresing variable in python 
Python :: python loop list 
Python :: all possible combinations in python 
Python :: table in sqlite python 
Python :: push notification using python 
Python :: python anytree 
Python :: numpy ndarray to matrix 
Python :: how to stop thread python 
Python :: how to handle missing values in dataset 
Python :: python staticmethod property 
Python :: python colored text into terminal 
Python :: python convert list of lists of strings to int 
Python :: python merge dict 
Python :: pandas groupby most frequent 
Python :: __lt__ 
Python :: how to check a string is empty in python 
Python :: ajouter element liste python 
Python :: free download django app for windows 10 
Python :: how to get a specific field in django 
Python :: python how to remove n from string 
Python :: python set attribute by string name 
Python :: create virtual environment python stack overflow 
Python :: rename all columns 
Python :: write string python 
Python :: python combinations 
Python :: Adding new column to existing DataFrame in Pandas using concat method 
Python :: kdeplot python 
Python :: Python - How To Check Operating System 
Python :: python filter list with lambda 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =