Show a random photo from an Unsplash collection
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Parnic e0994d8d12 Don't stack image load listeners
load() runs every updateInterval and called img1.addEventListener("load")
each time without removing the previous listener. Because the two images
swap ids after each fade, listeners accumulated on both (2 per hour at the
default interval), and every stacked copy ran on each new photo: N
concurrent fades, and N id swaps, which leave the ids unswapped when N is
even. Assigning img1.onload replaces the previous handler instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 08:49:24 -06:00
.gitignore Initial commit 2018-04-21 11:40:52 -05:00
CHANGELOG.md Fix images failing to load (#4) 2021-03-06 14:55:08 -06:00
LICENSE Initial commit 2018-04-21 11:40:52 -05:00
MMM-Unsplash.js Don't stack image load listeners 2026-11-26 08:49:24 -06:00
package.json Initial commit 2018-04-21 11:40:52 -05:00
README.md Updated readme 2019-01-07 22:43:26 -06:00

MMM-Unsplash

A MagicMirror² module used to pull a random photo from one or more Unsplash collections. Like MMM-RandomPhoto, but for specific collections. Tested with MagicMirror² v2.2.2, v2.3.1 servers, Chrome 65 on Windows 10 and Midori 0.4.3 on a Raspberry Pi Zero W with Raspbian Jessie.

Installation

  1. Navigate into your MagicMirror's modules folder and execute git clone https://github.com/parnic/MMM-Unsplash.git.
  2. Add the module inside config.js placing it where you prefer.

Config

Option Type Description Default
opacity double The opacity of the image. 0.3
collections string (REQUIRED) Comma-delimited list of collections to pull from. ''
width int Desired image width. 1080
height int Desired image height. 1920
orientation string Orientation of the image. Valid values: landscape, portrait, squarish 'portrait'
apiKey string (REQUIRED) Your Unsplash API key. ''
updateInterval int Number of seconds between image updates. Note that your API key is rate-limited, so if, for example, your rate limit was 50/hr, this should be no less than 72. 1800 (30mins)
divName string The ID of the div to use for the displayed image. This only needs to be set if you use something like MMM-ProfileSwitcher and/or need to be able to load images from multiple Unsplash modules at once. 'mmm-unsplash-placeholder'

Here is an example of an entry in config.js

{
	module: 'MMM-Unsplash',
	position: 'fullscreen_below',
	config: {
		collections: '369966,1240111,1136512,629911,150672,920773',
		apiKey: 'your_api_key'
	}
},

Notes

Pull requests are very welcome! If you'd like to see any additional functionality, don't hesitate to let me know.

Dependencies

None!

Special Thanks

MMM-RandomPhoto for the inspiration. The core image update functionality is cribbed from this module.