Skip to content

Instantly share code, notes, and snippets.

@coolbluewillem
Created January 13, 2015 12:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolbluewillem/9481e71177ccb5670841 to your computer and use it in GitHub Desktop.
Save coolbluewillem/9481e71177ccb5670841 to your computer and use it in GitHub Desktop.
Photoshop script (.jsx) resizing icons automatically for iOS devices and create different Retina versions (@2x & @3x)
try
{
var inputFolder = Folder.selectDialog("Select a folder to process");
var fileList = inputFolder.getFiles("*.png");
var initialPrefs = app.preferences.rulerUnits; // will restore at end
app.preferences.rulerUnits = Units.PIXELS; // use pixels
var destFolder = Folder.selectDialog( "Choose an output folder");
var x2Folder = new Folder ( destFolder + "/@2x");
x2Folder.create();
var x3Folder = new Folder ( destFolder + "/@3x");
x3Folder.create();
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.PNG;
sfw.PNG8 = false; // use PNG-24
sfw.transparency = true;
var i, j;
stripFileName = function(fileName){
return fileName.substring(0, (doc.name.length - 4));
}
for(i=0; i<fileList.length; i++) {
var doc = open(fileList[i], OpenDocumentType.PNG);
var icons = [
{"name": stripFileName(doc.name) + "@2x.png", "size":70, "folder": "/@2x/" },
{"name": stripFileName(doc.name) + "@3x.png", "size":105, "folder": "/@3x/" }
];
var destIcon;
var destFileName;
for (j = 0; j < icons.length; j++)
{
destIcon = icons[j];
doc.resizeImage(destIcon.size, destIcon.size, // width, height
null, ResampleMethod.BICUBICSHARPER);
destFileName = destIcon.name;
doc.exportDocument(new File(destFolder + destIcon.folder + destFileName), ExportType.SAVEFORWEB, sfw);
}
doc.close(SaveOptions.DONOTSAVECHANGES);
}
alert("iOS icons created!");
}
catch (exception)
{
if ((exception != null) && (exception != ""))
alert(exception);
}
finally
{
if (doc != null)
doc.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = initialPrefs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment