Skip to content

Instantly share code, notes, and snippets.

@brickpop
Last active July 27, 2016 16:59
Show Gist options
  • Save brickpop/1b5a5ce9b864132db6c0c020e211e7cd to your computer and use it in GitHub Desktop.
Save brickpop/1b5a5ce9b864132db6c0c020e211e7cd to your computer and use it in GitHub Desktop.
Gulp iOS/Android icon/splash generator
var gulp = require('gulp');
// ICONS
gulp.task('icons', function() {
var lwip = require('lwip');
// Default
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(57, 57).writeFile('resources/ios/icon/icon.png', 'png', {transparency: 'auto'}, function(){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(57*2, 57*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// 40
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(40, 40).writeFile('resources/ios/icon/icon-40.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(40*2, 40*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// 50
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(50, 50).writeFile('resources/ios/icon/icon-50.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(50*2, 50*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// 60
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(60, 60).writeFile('resources/ios/icon/icon-60.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(60*2, 60*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(60*3, 60*3).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// 72
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(72, 72).writeFile('resources/ios/icon/icon-72.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(72*2, 72*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// 76 (no cal?)
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(76, 76).writeFile('resources/ios/icon/icon-76.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(76*2, 76*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// small (push)
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(29, 29).writeFile('resources/ios/icon/icon-small.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(29*2, 29*2).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(29*3, 29*3).writeFile('resources/ios/icon/[email protected]', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
// Android
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(36, 36).writeFile('resources/android/icon/drawable-ldpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(48, 48).writeFile('resources/android/icon/drawable-mdpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(72, 72).writeFile('resources/android/icon/drawable-hdpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(96, 96).writeFile('resources/android/icon/drawable-xhdpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(144, 144).writeFile('resources/android/icon/drawable-xxhdpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
lwip.open('resources/icon.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(192, 192).writeFile('resources/android/icon/drawable-xxxhdpi-icon.png', 'png', {transparency: 'auto'}, function(err){if(err)console.error(err);});
});
});
// SPLASH SCREENS
gulp.task('splash', function() {
var PSD = require('psd');
console.log("Converting PSD to PNG...");
PSD.open("resources/splash-template.psd")
.then(function(psd) {
return psd.image.saveAsPng('resources/splash.png');
}).then(function() {
var lwip = require('lwip');
console.log("Generating iPhone and Android versions...");
// Default~iphone.png" width="320" height="480"
// Default@2x~iphone.png" width="640" height="960"
// Default-568h@2x~iphone.png" width="640" height="1136"
// Default-667h.png" width="750" height="1334"
// Default-736h.png" width="1242" height="2208"
// Default-Portrait~ipad.png" width="768" height="1024"
// Default-Portrait@2x~ipad.png" width="1536" height="2048"
// IOS
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(320, 480).writeFile('resources/ios/splash/Default~iphone.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(320*2, 480*2).writeFile('resources/ios/splash/Default@2x~iphone.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(320*2, 568*2).writeFile('resources/ios/splash/Default-568h@2x~iphone.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(375*2, 667*2).writeFile('resources/ios/splash/Default-667h.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(414*3, 736*3).writeFile('resources/ios/splash/Default-736h.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(768, 1024).writeFile('resources/ios/splash/Default-Portrait~ipad.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(768*2, 1024*2).writeFile('resources/ios/splash/Default-Portrait@2x~ipad.png', function(err){if(err)console.error(err);});
});
// ANDROID
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(240, 320).writeFile('resources/android/splash/drawable-port-ldpi-screen.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(320, 480).writeFile('resources/android/splash/drawable-port-mdpi-screen.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(480, 800).writeFile('resources/android/splash/drawable-port-hdpi-screen.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(720, 1280).writeFile('resources/android/splash/drawable-port-xhdpi-screen.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(960, 1600).writeFile('resources/android/splash/drawable-port-xxhdpi-screen.png', function(err){if(err)console.error(err);});
});
lwip.open('resources/splash.png', function(err, image){
if(err) return console.error(err);
image.batch().cover(1280, 1920).writeFile('resources/android/splash/drawable-port-xxxhdpi-screen.png', function(err){if(err)console.error(err);});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment