Skip to content

Instantly share code, notes, and snippets.

@sxua
Created September 3, 2014 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sxua/5a04ae95f5d01793352c to your computer and use it in GitHub Desktop.
Save sxua/5a04ae95f5d01793352c to your computer and use it in GitHub Desktop.
Illustrator script for saving drawables
/**
* 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 imageName;
if (document && folder) {
imageName = prompt("Image Name", "") || "";
}
if (document && folder) {
saveToRes(100, imageName, "", imageName + "-iOS", false);
saveToRes(200, imageName, "@2x", imageName + "-iOS", false);
saveToRes(300, imageName, "@3x", imageName + "-iOS", false);
saveToRes(100, imageName, "", "drawable-mdpi", true);
saveToRes(150, imageName, "", "drawable-hdpi", true);
saveToRes(200, imageName, "", "drawable-xhdpi", true);
saveToRes(300, imageName, "", "drawable-xxhdpi", true);
saveToRes(400, imageName, "", "drawable-xxxhdpi", true);
}
/**
* Scale and export file suffixed by densitySuffix, in a specific folder named folderName
*/
function saveToRes(scaleTo, fileName, densitySuffix, folderName, android) {
var i, ab, file, options;
var myFolder = new Folder(folder.absoluteURI + "/" + folderName);
if (!myFolder.exists) myFolder.create();
for (i = document.artboards.length - 1; i >= 0; i--) {
if (android) {
fileName = fileName.replace(/\-/g, "_");
}
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);
}
}
function isUpperCase(myString) {
return (myString == myString.toUpperCase());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment