Created
June 22, 2017 23:46
-
-
Save brito/122fae0c62ed127860ba143eecb89c92 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
Resources generator | |
Generate icons for mobile/tablet according to iOS/Android specifications. | |
Takes an image 'icon.png' and outputs to pre-existing directories res/* | |
Requires Imagemagick (imagemagick.org) | |
See Also: ninepatch.js; Android 9-patch (http://developer.android.com/tools/help/draw9patch.html) | |
TODO: iOS html splash | |
circa 2015 | |
*/ | |
(function(specification) { | |
var shell = require('child_process'); | |
for (var location in specification){ | |
// create directories if necessary | |
var mkdirp = 'mkdir -p ' + location; | |
//console.log(mkdirp); | |
shell.exec(mkdirp, out); | |
// create each variant in each target directory | |
for (var namesize in specification[location]) | |
(location + specification[location][namesize]) | |
.replace(/(^\S+) (\d+)x(\d+)?/, | |
function(spec, output, width, height) { | |
var convert = '/opt/local/bin/convert icon.png ' + | |
(width == height ? | |
// create icon | |
'-resize ' + width : | |
// or create splashscreen | |
'-gravity center' + | |
' -resize ' + Math.floor((Math.min(width, height)) / 5.333) + | |
' -extent ' + width + 'x' + height) | |
+ ' ' + output; | |
console.log(convert); | |
shell.exec(convert, out); | |
}); | |
} | |
})({ | |
'res/ios/': [ | |
'iTunesArtwork.png 1024x1024', | |
'Icon-120.png 120x120', | |
'[email protected] 180x180', | |
'Icon-76.png 76x76', | |
'[email protected] 167x167', | |
'[email protected] 152x152', | |
'[email protected] 640x960', | |
'[email protected] 640x1136', | |
'[email protected] 750x1334', | |
'[email protected] 1242x2208', | |
'[email protected] 2208x1242', | |
'Default-PortraitRetina.png 768x1024', | |
'[email protected] 1536x2048', | |
'Default-LandscapeRetina.png 1024x768', | |
'[email protected] 2048x1536', | |
'[email protected] 2208x1242', | |
'Icon-40.png 40x40', | |
'[email protected] 80x80', | |
'[email protected] 120x120', | |
'Icon-29.png 29x29', | |
'[email protected] 80x80', | |
'[email protected] 87x87' | |
], | |
'res/android/': [ | |
'display-ldpi-icon.png 36x36', | |
'display-mdpi-icon.png 48x48', | |
'display-hdpi-icon.png 72x72', | |
'display-xhdpi-icon.png 96x96', | |
'display-xxhdpi-icon.png 144x144', | |
'display-xxxhdpi-icon.png 192x192' | |
] | |
}); | |
function out(error, stdout, stderr) { | |
stdout && console.log(stdout); | |
stderr && console.log(stderr); | |
if (error) | |
console.log(error); | |
} | |
/* | |
see also: | |
search: | |
"icons for universal apps" site:developer.apple.com | |
https://developer.apple.com/library/ios/qa/qa1686/_index.html | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment