Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create FPO imagery from strings.
const http = require('http')
const fs = require('fs')
let imgs = [
"Image 1 Name",
"Image 2 Name",
"Image 3 Name",
]
const slugify = text =>
text.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '')
const downloadFPO = text => {
const filename = slugify(text)
console.log(`Downloading ${filename}.`)
const f = fs.createWriteStream(`./${filename}.jpg`)
http.get(`http://via.placeholder.com/500/000000/ffffff?text=${encodeURI(text)}`, rsp => {
rsp.pipe(f)
f.on('finish', () => {
f.close()
downloadNextFile()
})
})
}
const downloadNextFile = () => {
if (imgs.length) {
downloadFPO(imgs.pop())
} else [
console.log('Donezo.')
]
}
downloadNextFile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment