Skip to content

Instantly share code, notes, and snippets.

@yuki-takeichi
Last active August 29, 2015 14:07
Show Gist options
  • Save yuki-takeichi/4d267b1ff5b6961293ae to your computer and use it in GitHub Desktop.
Save yuki-takeichi/4d267b1ff5b6961293ae to your computer and use it in GitHub Desktop.
Save iOS Retina images
/**
* Remixer 1: @herkulano (http://www.herkulano.com)
* Remixer 2: @hotappsfactory (http://www.hotappsfactory.com)
* Thanks to: Niels Bosma (niels.bosma@motorola.com)
*/
var folder = Folder.selectDialog();
var document = app.activeDocument;
var suffix = "";
//if (document && folder) {
// suffix = prompt("Prefix", "") || "";
//}
if (document && folder) {
var documentName = document.name.replace(".ai","");
saveToRes(100, documentName, "");
saveToRes(200, documentName, "@2x");
saveToRes(300, documentName, "@3x");
}
/**
* Scale and export file suffixed by densitySuffix
*/
function saveToRes(scaleTo, preffix, densitySuffix) {
var i, ab, file, options;
var myFolder = new Folder(folder.absoluteURI);
for (i = document.artboards.length - 1; i >= 0; i--) {
document.artboards.setActiveArtboardIndex(i);
ab = document.artboards[i];
var fileName = preffix + /* ab.name + */ suffix;
file = new File(myFolder.fsName + "/" + fileName + densitySuffix + ".png");
options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
options.verticalScale = scaleTo;
options.horizontalScale = scaleTo;
document.exportFile(file, ExportType.PNG24, options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment