Skip to content

Instantly share code, notes, and snippets.

@Meandmybadself
Created August 14, 2018 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Meandmybadself/e99e7be6b939275ec992805c05b4c195 to your computer and use it in GitHub Desktop.
Save Meandmybadself/e99e7be6b939275ec992805c05b4c195 to your computer and use it in GitHub Desktop.
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