Many Pictures
Generating a random image is fun; you never know what you're going to get! I've always thought it would be an interesting screensaver, so I made a small static site to do just that.
The problem
At 100 queries per day, the free API provided by Google image search won't work. A screensaver needs to be constantly producing interesting stuff! However, anyone can make requests to google images from a browser for free. We can take the straight forwards approach and "reverse engineer" the google search bar by making an HTTP request with the following query:
&tbm=isch tells google to only search images.
In my experience, this approach can fail inconsistently and tends to only get poor quality images. The higher quality version of an image likely requires some amount of additional steps that javascript performs when in browsers.
But there's a different approach. To beat both issues, I looked into Pixabay, a great website for finding free photos submitted by users. Most of these photos are pretty high in quality, given that they're forced to go through a layer of community voting first. And it just so happens that Pixabay has a really nice free API that fit my purposes!
How does it work?
Many Pictures is a screensaver website that uses Pixabay's public API to automatically scroll through images. It's purpose is for when you have an idle computer, such as a shared computer in a public space. The current version of Many Pictures scrolls through images in chronological order, so it never repeats.
You can also use the mouse's scroll wheel to increase and decrease the scroll speed.
Image 921 added to Pixabay, including the layout of Many Pictures
More problems
Pixabay's free API has a limit of 100 requests per minute. If the scroll speed ever loads images faster than once per 600ms, Many Pictures will detect it using a geometric average and throttle the scroll speed accordingly.
The geometric average time vs the exact time the image took to load, with scroll speed at the bottom
You can see in the above chart that the geometric average helps rough out any speedups / slowdowns caused by the time it takes to download each image. When recording this data, I only ever increased the scroll speed, while the algorithm slowed it down. You can see this on the bottom half of the chart.
A nice side-effect of this approach is that slowdowns are somewhat smooth, and typically occur all at once.
Try it out
To use Many Pictures you need your own API key. 100 images per minute is too shallow of a limit for more than a few people to use at a time, but luckily Pixabay API keys are free! Follow these steps to grab your own key & plug it into Many Pictures.
- Go to https://pixabay.com/api/docs/
- Create a free account & login
- Ctrl+F "Your API key:" & copy the key (highlighted in green)
- Go to https://many-pictures.github.io/ and input your api key in the top input box
- Press enter
- Enjoy!
woooooo~
Feel free to check out this website's source on GitHub if you'd like to see how I used the Pixabay API, or have any other questions