Skip to content

Instantly share code, notes, and snippets.

@tlinkner
Last active March 21, 2019 18:06
Show Gist options
  • Save tlinkner/3723395 to your computer and use it in GitHub Desktop.
Save tlinkner/3723395 to your computer and use it in GitHub Desktop.
Photoshop script to output iOS icons, now with iOS 8 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. Exting 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(60,2);
resize(60,3);
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);
}
@arventwei
Copy link

nice work

@lai3d
Copy link

lai3d commented May 16, 2016

Nice work!

@mdzigurski
Copy link

nice work!

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