“Unduh gambar Unsplash” Kode Jawaban

Unduh gambar Unsplash

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
James Prentor

Gambar unsplash

unsplash.photos.getPhoto("pFqrYbhIAXs");
Plain Puma

Jawaban yang mirip dengan “Unduh gambar Unsplash”

Pertanyaan yang mirip dengan “Unduh gambar Unsplash”

Lebih banyak jawaban terkait untuk “Unduh gambar Unsplash” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya