Created
January 24, 2019 01:28
-
-
Save 7coil/3972c69ec5698a0625071fc58baa6614 to your computer and use it in GitHub Desktop.
This application turns numbered pictures in a `frames` folder into the `project` folder as hashed files, and creates the corresponding JSON to insert into the project.
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 fs = require('fs'); | |
const path = require('path'); | |
const crypto = require('crypto'); | |
const compare = (a, b) => parseInt(a.replace(/\D/g, ''), 10) - parseInt(b.replace(/\D/g, ''), 10); | |
const data = fs.readdirSync('./frames') | |
.sort(compare) | |
.map((file, index) => { | |
const hash = crypto.createHash('md5').update(fs.readFileSync(`./frames/${file}`)).digest('hex'); | |
const extension = path.extname(file).replace('.', ''); | |
fs.copyFileSync(`./frames/${file}`, `./project/${hash}.${extension}`) | |
return { | |
assetId: hash, | |
name: `image${index}`, | |
bitmapResolution: 2, | |
md5ext: `${hash}.${extension}`, | |
dataFormat: extension, | |
rotationCenterX: 640, | |
rotationCenterY: 360 | |
}; | |
}); | |
fs.writeFileSync('files.json', JSON.stringify(data, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment