Skip to content

Instantly share code, notes, and snippets.

@jerrythomas
Created October 17, 2018 04:45
Show Gist options
  • Save jerrythomas/f654ff22ac5864fb814c066c7a0dc692 to your computer and use it in GitHub Desktop.
Save jerrythomas/f654ff22ac5864fb814c066c7a0dc692 to your computer and use it in GitHub Desktop.
Generate App Icons
const sharp = require('sharp');
const fs = require('fs-extra');
function generateIcons(sourceFile){
let sizes = [512, 384, 256, 192, 152, 144, 128, 96, 72, 32];
fs.ensureDirSync('assets/icons');
sizes.forEach(size => {
let iconFile = `assets/icons/icon-${size}x${size}.png`;
if (size == 32)
iconFile = 'favicon.ico';
sharp(sourceFile)
.resize(size, size)
.toFile(iconFile, function (err) {
if (err) {
console.error(`Error while generating ${iconFile}`);
console.error(err);
}
});
});
}
var args = process.argv.slice(2);
console.log(args[0]);
generateIcons(args[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment