Last active
August 22, 2017 08:04
-
-
Save lionello/ae1a9d91d78aad0e617a2ef06c3d9950 to your computer and use it in GitHub Desktop.
Node.JS script to losslessly convert an iOS .imageset to an Android mipmap
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
#!/usr/bin/env node | |
const FS = require('fs') | |
const Path = require('path') | |
const FolderMap = { | |
"1x": "mipmap-mdpi", | |
"2x": "mipmap-xhdpi", | |
"3x": "mipmap-xxhdpi", | |
} | |
const srcfolder = process.argv[2] | |
if (srcfolder === undefined) { | |
console.log(`Usage: ${process.argv[1]} IMAGESET [RES_FOLDER]`) | |
process.exit(2) | |
} | |
const destfolder = process.argv[3] | |
const json = JSON.parse(FS.readFileSync(Path.join(srcfolder, 'Contents.json'))) | |
json.images.forEach(img => { | |
const destname = Path.basename(srcfolder, ".imageset") + Path.extname(img.filename) | |
const dest = Path.join(destfolder ? destfolder : ".", FolderMap[img.scale], destname) | |
const src = Path.join(srcfolder, img.filename) | |
console.log(src, '->', dest) | |
FS.createReadStream(src).pipe(FS.createWriteStream(dest)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment