Created
August 14, 2018 15:15
-
-
Save Meandmybadself/e99e7be6b939275ec992805c05b4c195 to your computer and use it in GitHub Desktop.
Create FPO imagery from strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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