Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

download images off unsplash 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 :: remove vowels in a string python 
Python :: max between two numbers python 
Python :: Reverse an string Using Extended Slice Syntax in Python 
Python :: django url with string parameter 
Python :: how to make a button open a new window in python 
Python :: python while 
Python :: python module location 
Python :: python try except: print error 
Python :: python not in 
Python :: pop list python 
Python :: requests save file python 
Python :: how to read .xlsx file in python 
Python :: isodate in python 
Python :: django bulk update 
Python :: Login script using Python and SQLite 
Python :: python __lt__ magic method 
Python :: numpy random 
Python :: python panda count excel sheet 
Python :: isnotin python 
Python :: python coding language 
Python :: change markersize in legend matplotlib 
Python :: pafy doc 
Python :: how to make a superuser in django 
Python :: var_dump in python 
Python :: write python 
Python :: pandas fillna with none 
Python :: python list add to start 
Python :: VALUE ERROR EXCEPTION 
Python :: how to create a button using tkinter 
Python :: pandas filter column with or 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =