Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

download unsplash images python without 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 :: download unsplash images 
Python :: try catch python with open 
Python :: flask form 
Python :: python how to insert values into string 
Python :: group by dateime pandas 
Python :: python integer to octal 
Python :: pandas dataframe any along row 
Python :: pytorch check if tensor is on gpu 
Python :: liste compréhension python 
Python :: turtle graphics documentation|pensize 
Python :: split paragraphs in python 
Python :: wifite subsystem 
Python :: marshmallow default value 
Python :: python decorator 
Python :: oops concept in python 
Python :: sort dict 
Python :: how to sort a list in python 
Python :: how to print during multiprocessing 
Python :: color plt 
Python :: appending items to a tuple python 
Python :: how to convert response to beautifulsoup object 
Python :: access column pandas 
Python :: python os get dir path 
Python :: how to take space separated input in pyhon dicationary 
Python :: python3.8 
Python :: continue and break in python 
Python :: how to code a trading bot in python 
Python :: brute force string matching algorithm in python 
Python :: isolationforest estimators 
Python :: flask rest api upload image 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =