Generate Random Images From Unsplash Without Using The API

June 24, 2018 by Andreas Wik

In case you haven’t heard already – Unsplash is the place to go when you need royalty free photos to use in your projects, whether it’s for commercial use or not. I use it myself quite often, for large background images. So does https://pixelarity.com, just to name an example.

While they do have a great API for developers, they also give you the option to simply access random images via URL’s.

Here’s an example, generating a completely random image from their massive storage:

https://source.unsplash.com/random

https://source.unsplash.com/random

 

Specific User

We can also generate a random image from a specific user. The URL format would be like so:

https://source.unsplash.com/user/USERNAME

Click this link below to generate a random image from the user wsanter:

https://source.unsplash.com/user/wsanter

 

Specific Sizes

There’s also an option to set the size of the image you want generated. Like so:

https://source.unsplash.com/random/WIDTHxHEIGHT

Let’s generate a random image with the width and height of 300px:

https://source.unsplash.com/random/300×300

 

Random Image From Search Term

This one is really cool. You can generate images from search terms. Let’s search for city and night (so fkn creative):

https://source.unsplash.com/random/?city,night

https://source.unsplash.com/random/?city,night

You place the search terms at the end of the URL, so before you could add the size if you’d like:

https://source.unsplash.com/random/900×700/?fruit

https://source.unsplash.com/random/900×700/?fruit

 

An Example With JavaScript

Here’s a simple CodePen I put together illustrating how you could use this dynamically with JavaScript:

See the Pen zaaXEZ by Andreas Wik (@andreaswik) on CodePen.

 

For a full list of features – check out the Unsplash Source documentation.

Have fun!

Share this article

Recommended articles

@awikio