Skip to content

Instantly share code, notes, and snippets.

@zadr
Last active Mar 30, 2017
Embed
What would you like to do?
one-off Adobe Illustrator script to export a document with one artboard to iOS app icons
var originalDocumentSize = 1024
var folder = Folder.selectDialog();
var document = app.activeDocument;
document.artboards.setActiveArtboardIndex(0);
if (document && document.artboards[0]) {
// Icons for Universal Apps; https://developer.apple.com/library/content/qa/qa1686/_index.html
scaleArtboardAndSave((512 / originalDocumentSize) * 100);
scaleArtboardAndSave((1024 / originalDocumentSize) * 100);
scaleArtboardAndSave((120 / originalDocumentSize) * 100);
scaleArtboardAndSave((180 / originalDocumentSize) * 100);
scaleArtboardAndSave((76 / originalDocumentSize) * 100);
scaleArtboardAndSave((152 / originalDocumentSize) * 100);
scaleArtboardAndSave((167 / originalDocumentSize) * 100);
scaleArtboardAndSave((20 / originalDocumentSize) * 100);
scaleArtboardAndSave((40 / originalDocumentSize) * 100);
scaleArtboardAndSave((60 / originalDocumentSize) * 100);
scaleArtboardAndSave((80 / originalDocumentSize) * 100);
scaleArtboardAndSave((120 / originalDocumentSize) * 100);
scaleArtboardAndSave((29 / originalDocumentSize) * 100);
scaleArtboardAndSave((58 / originalDocumentSize) * 100);
scaleArtboardAndSave((87 / originalDocumentSize) * 100);
}
function scaleArtboardAndSave(scaleTo) {
var cwd = new Folder(folder.absoluteURI + "/");
var sizeInPixels = scaleTo / 100 * originalDocumentSize;
var fileName = "icon-" + sizeInPixels + ".png";
var file = new File(cwd.fsName + "/" + "icon-" + sizeInPixels + ".png");
// http://cssdk.s3-website-us-east-1.amazonaws.com/sdk/1.0/docs/WebHelp/references/csawlib/com/adobe/illustrator/ColorDitherMethod.html
var options = new ExportOptionsPNG24();
options.antiAliasing = 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