const fs = require('fs') const sharp = require('sharp') const inky = require('@aeroniemi/inky') const frame = new inky.Impression73() const folder = '../album/' var filelist = false function loadImgs() { fs.readdir(folder, (err, files) => { if (err || files.length == 0) { console.log('No images found. Exiting.') process.exit(1) } else { console.log(files.length + ' images found. Starting album display...') filelist = files displayAlbum() } }) } function displayAlbum() { if (filelist.length == 0) loadImgs() else { imgref = Math.floor(Math.random() * filelist.length) imgfile = filelist.splice(imgref, 1)[0] console.log('Randomly displaying image ' + (imgref + 1) + ' of ' + (filelist.length + 1) + ' remaining: ' + imgfile) displayImage(imgfile) setTimeout(displayAlbum, 900000) } } function displayImage(filename) { sharp(folder + filename) .resize(800,480) .toFile('output.png', (err, info) => { frame.display_png('output.png') frame.show() }) } loadImgs()