Skip to content

Instantly share code, notes, and snippets.

@ngs
Forked from ma11hew28/Create Icons.jsx
Created May 22, 2012 23:26
Show Gist options
  • Save ngs/2772315 to your computer and use it in GitHub Desktop.
Save ngs/2772315 to your computer and use it in GitHub Desktop.
Photoshop Script to Create iPhone Icons from iTunesArtwork
/** @see http://bit.ly/JPvZ11 */
// Turn debugger on. 0 is off.
// $.level = 1;
var OUTPUT_FOLDER_NAME = "icons"
, icons = [
["iphone_icon_29x29", 29],
["iphone_icon_40x40", 40],
["iphone_icon_60x60", 60],
["ipad_icon_29x29", 29],
["ipad_icon_40x40", 40],
["ipad_icon_76x76", 76]
]
, exportOptions = new ExportOptionsSaveForWeb()
;
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // use PNG-24
exportOptions.transparency = false;
function main() {
var initialPrefs = app.preferences.rulerUnits
, dialogUsed = false
, file, doc, folder
;
if(app.documents.length)
doc = app.activeDocument;
else {
file = File.openDialog("Select the iTunesArtwork file.");
if(!file) return;
doc = open(file);
dialogUsed = true;
}
folder = Folder.selectDialog ("Select folder to output");
app.preferences.rulerUnits = Units.PIXELS;
folder && exportIcons(doc, folder);
dialogUsed && doc.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = initialPrefs;
}
function exportIcons(doc, folder) {
for(var i = 0, j = 0, icon; icon = icons[i++]; j = 0) {
for(j=1; j<=3; j++)
exportIcon(doc, folder, icon[0], icon[1], j);
}
}
function exportIcon(doc, folder, name, size, scale) {
var dup;
size *= scale;
if(scale > 1)
name += "@" + scale + "x";
dup = doc.duplicate(name, true);
dup.resizeImage(size, size, null, ResampleMethod.BICUBICSHARPER);
dup.exportDocument(new File(folder + "/" + name + ".png"), ExportType.SAVEFORWEB, exportOptions);
dup.close(SaveOptions.DONOTSAVECHANGES);
}
main();
/** @see http://bit.ly/VTacev */
// Turn debugger on. 0 is off.
// $.level = 1;
var OUTPUT_FOLDER_NAME = "icons"
, icons = [
["icon_32x32", 16],
["icon_32x32", 32],
["icon_128x128", 128],
["icon_256x256", 256],
["icon_512x512", 512]
]
, exportOptions = new ExportOptionsSaveForWeb()
;
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // use PNG-24
exportOptions.transparency = true;
function main() {
var initialPrefs = app.preferences.rulerUnits
, dialogUsed = false
, file, doc, folder
;
if(app.documents.length)
doc = app.activeDocument;
else {
file = File.openDialog("Select the iTunesArtwork file.");
if(!file) return;
doc = open(file);
dialogUsed = true;
}
folder = Folder.selectDialog ("Select folder to output");
app.preferences.rulerUnits = Units.PIXELS;
folder && exportIcons(doc, folder);
dialogUsed && doc.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = initialPrefs;
}
function exportIcons(doc, folder) {
for(var i = 0, j = 0, icon; icon = icons[i++]; j = 0)
do exportIcon(doc, folder, icon[0], icon[1], !!j) while(!(j++));
}
function exportIcon(doc, folder, name, size, retina) {
var dup;
if(retina) {
size *= 2;
name += "@2x";
}
dup = doc.duplicate(name, true);
dup.resizeImage(size, size, null, ResampleMethod.BICUBICSHARPER);
dup.exportDocument(new File(folder + "/" + name + ".png"), ExportType.SAVEFORWEB, exportOptions);
dup.close(SaveOptions.DONOTSAVECHANGES);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment