Skip to content

Instantly share code, notes, and snippets.

@arjankuijpers
Forked from tlinkner/Output iOS Icons.jsx
Last active September 4, 2016 13:13
Show Gist options
  • Save arjankuijpers/b9643857e4ec5f27e7fd12adebf89d7e to your computer and use it in GitHub Desktop.
Save arjankuijpers/b9643857e4ec5f27e7fd12adebf89d7e to your computer and use it in GitHub Desktop.
Photoshop script to output iOS icons, now with iOS 9 sizes
// Output iOS Icons.jsx
// 2014 Todd Linkner
// License: none (public domain)
// v1.2
//
// This script is for Photoshop CS6. It outputs iOS icons of the following
// sizes from a source 1024px x 1024px PSD
//
// [name]-29.png
// [name][email protected]
// [name][email protected]
// [name]-40.png
// [name][email protected]
// [name][email protected]
// [name][email protected]
// [name][email protected]
// [name]-76.png
// [name][email protected]
// [name]-512.png (512px x 512px)
// [name][email protected] (1024px x 1024px)
// bring Photoshop into focus
#target Photoshop
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. Exiting script.";
// Open file
open(inputFile);
// Set ruler untis to pixels
app.preferences.typeUnits = TypeUnits.PIXELS
// iOS 8 Icons
resize(29,1);
resize(29,2);
resize(29,3);
resize(40,1);
resize(40,2);
resize(40,3);
resize(50,1);
resize(50,2);
resize(57,1);
resize(57,2);
resize(60,2);
resize(60,3);
resize(72,1);
resize(72,2);
resize(83.5,2);
resize(76,1);
resize(76,2);
resize(512,1);
resize(512,2);
// Clean up
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert("Done!");
}
function resize(size,scaleFactor) {
// Setup file name
var pname = app.activeDocument.path + "/";
var fname = app.activeDocument.name;
var append = "";
var fsize = size * scaleFactor;
if (scaleFactor > 1) {
append = "@" + scaleFactor + "x";
}
n = fname.lastIndexOf(".");
if (n > 0) {
var basename = fname.substring(0,n);
fname = basename+"-"+size+append+".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(fsize+"px",fsize+"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