Skip to content

Instantly share code, notes, and snippets.

@Technologx2013
Forked from tlinkner/Output iOS Icons.jsx
Created July 14, 2014 19:45
Show Gist options
  • Save Technologx2013/ca1ec3994c8e7eb0971e to your computer and use it in GitHub Desktop.
Save Technologx2013/ca1ec3994c8e7eb0971e to your computer and use it in GitHub Desktop.
// Output iOS Icons.jsx
// 2012 Todd Linkner
// License: none (public domain)
// v1.1
//
// This script is for Photoshop CS6. It outputs iOS icons of the following
// sizes from a source 1024px x 1024px PSD
//
// iOS7 App Icon:
// [name][email protected] (120px x 120px)
//
// iOS7 App Icon:
// [name][email protected] (152px x 152px)
// [name]-76.png (76px x 76px)
//
// iPhone App Icon:
// [name][email protected] (114px x 114px)
// [name]-57.png (57px x 57px)
//
// iPhone Settings/Search Results:
// [naem][email protected] (58px x 58px)
// [name]-29.png (29px x 29px)
//
// iPad App Icon:
// [name][email protected] (144px x 144px)
// [name]-72.png (72px x 72px)
//
// iPad Settings/Search Results:
// [naem][email protected] (100px x 100px)
// [name]-50.png (50px x 50px)
//
// iTunes:
// [name]-512.png (512px x 512px)
// [name][email protected] (1024px x 1024px)
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>$$$/JavaScripts/OutputiOSIcons/MenuAlt=Output iOS Icons</name>
<category>mobile</category>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
*/
// bring Photoshop into focus
#target Photoshop CS6
main();
function main() {
alert("This script outputs iPhone, iPad, and iTunes icons, "
+ "from a 1024px x 1024px PSD source file.\r\r");
// Ask user for input folder
var inputFile = File.openDialog("Select a 1024px x 1024px PSD file","PSD File:*.psd");
if (inputFile == null) throw "No file selected. Exting script.";
// Open file
open(inputFile);
// Set ruler untis to pixels
app.preferences.typeUnits = TypeUnits.PIXELS
// iOS 7 Icons
resize(120,'@2x');
resize(152,'@2x');
resize(76);
// iPhone App Icon:
resize(114,'@2x');
resize(57);
// iPhone Settings/Search Results:
resize(58,'@2x');
resize(29);
// iPad App Icon:
resize(144,'@2x');
resize(72);
// iPad Settings/Search Results:
resize(100,'@2x');
resize(50);
// iTunes:
resize(1024,'@2x');
resize(512);
// Clean up
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert("Done!");
}
function resize(size,append) {
// Setup file name
var pname = app.activeDocument.path + "/";
var fname = app.activeDocument.name;
n = fname.lastIndexOf(".");
if (n > 0) {
basename = fname.substring(0, n);
if (undefined != append) {
fname = basename+"-"+(size/2)+append+".png";
} else {
fname = basename+"-"+size+".png";
}
}
// Set export options
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.transparency = true;
opts.interlaced = 0;
opts.includeProfile = false;
opts.optimized = true;
// Duplicate, resize and export
var tempfile = app.activeDocument.duplicate();
tempfile.resizeImage(size+"px",size+"px");
file = new File(pname+fname);
tempfile.exportDocument(file, ExportType.SAVEFORWEB, opts);
tempfile.close(SaveOptions.DONOTSAVECHANGES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment