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 :: python dict to string 
Python :: .size pandas 
Python :: how to sum numpy matrix diagonal 
Python :: python using list as dictionary key 
Python :: python black 
Python :: size pilimage 
Python :: groupbycolumn 
Python :: class chain methods python 
Python :: access cmd with python 
Python :: create table numpy 
Python :: list addition within a list comprehension 
Python :: python largest common divisor 
Python :: call shell script from python 
Python :: Finding if 2 consecutive numbers in a list have a sum equal to a given number 
Python :: get_or_create in django 
Python :: django-tool-bar 
Python :: reactstrap example 
Python :: try except to specific line 
Python :: scroll to top selenium python 
Python :: python dictionary get vs setdefault 
Python :: make virtual environment python 
Python :: tkinter change button foreground 
Python :: extract decimal number from string python 
Python :: basic flask api 
Python :: Maximize Difference codechef solution 
Python :: pythagoras theorem formula 
Python :: uninstall python ubuntu 18.04 
Python :: python invert colormap 
Python :: sorted python 
Python :: best python books python 3 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =