Skip to content

Instantly share code, notes, and snippets.

@luciuskwok
Created September 3, 2013 21:46
Show Gist options
  • Save luciuskwok/6430039 to your computer and use it in GitHub Desktop.
Save luciuskwok/6430039 to your computer and use it in GitHub Desktop.
Takes the currently open document and exports it in the standard iOS app icon sizes. This script is designed for Photoshop CS5. This version handles scaling styles correctly.
// Export iOS App Icons
// by Lucius Kwok
// Takes the currently open document and exports it in the standard iOS app icon sizes.
// This script is designed for Photoshop CS5.
// To install, place this file in the /Applications/Adobe Photoshop CS5/Presets/Scripts/ folder.
function resizeDoc(width) {
var desc = new ActionDescriptor();
desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), width );
desc.putBoolean( stringIDToTypeID('scaleStyles'), true );
desc.putBoolean( charIDToTypeID('CnsP'), true );
desc.putEnumerated( charIDToTypeID('Intr'), charIDToTypeID('Intp'), stringIDToTypeID('bicubic') );
executeAction( charIDToTypeID('ImgS'), desc, DialogModes.NO );
};
try {
var doc = app.activeDocument;
var startState = doc.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Check parameters.
if (doc.width != doc.height)
throw "Image is not square";
// Ask for Save folder.
var destFolder = Folder.selectDialog("Exporting iOS app icons as PNG.");
if (destFolder == null)
throw ""; // User canceled; just exit.
// Save icons in PNG using Save for Web.
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.PNG;
sfw.PNG8 = false; // use PNG-24
sfw.transparency = true;
doc.info = null; // delete metadata
var icons = [
{"name": "Icon-1024", "size":1024}, // App Store, iTunesArtwork@2x (Retina)
{"name": "Icon-512", "size":512}, // App Store, iTunesArtwork (non-Retina)
{"name": "Icon-152", "size":152}, // iOS 7: iPad (Retina)
{"name": "Icon-144", "size":144}, // iOS 6 and earlier: iPad (Retina)
{"name": "Icon-120", "size":120}, // iOS 7: iPhone (Retina)
{"name": "Icon-114", "size":114}, // iOS 6 and earlier: iPhone (Retina)
{"name": "Icon-100", "size":100},
{"name": "Icon-80", "size":80}, // Spotlight search results (Retina)
{"name": "Icon-76", "size":76}, // iOS 7: iPad (non-Retina)
{"name": "Icon-72", "size":72}, // iOS 6 and earlier: iPad (non-Retina)
{"name": "Icon-58", "size":58}, // Settings icon (Retina)
{"name": "Icon-57", "size":57}, // iOS 6 and earlier: iPhone (non-Retina)
{"name": "Icon-50", "size":50},
{"name": "Icon-40", "size":40}, // Spotlight search results (non-Retina)
{"name": "Icon-29", "size":29} // Settings icon (non-Retina)
];
var icon, i;
for (i=0; i<icons.length; i++) {
icon = icons[i];
var sizeUnitValue = UnitValue(icon.size, 'px');
resizeDoc(icon.size)
// doc.resizeImage(sizeUnitValue, sizeUnitValue, 72, ResampleMethod.BICUBICSHARPER);
var destFileName = icon.name + ".png";
doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
doc.activeHistoryState = startState; // undo resize
}
}
catch (exception) {
if ((exception != null) && (exception != ""))
alert(exception);
}
finally {
app.preferences.rulerUnits = initialPrefs; // restore prefs
}
@mackoj
Copy link

mackoj commented Dec 23, 2013

Does it work with SVG based images ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment