Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Node.JS script to losslessly convert an iOS .imageset to an Android mipmap
#!/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]`)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment