-
Notifications
You must be signed in to change notification settings - Fork 19
/
Create_Icons.jsx
207 lines (168 loc) · 7.02 KB
/
Create_Icons.jsx
1
#target photoshop// Photoshop Script to Create Icons//// Prerequisite:// First, create at least a 1024x1024 px PNG file according to:// https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/app-icon///// Install - Save Create Icons.jsx to:// Win: C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit CS5\SDK// Mac: /Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS5/SDK// * Restart Photoshop//// Update:// * Just modify & save, no need to resart Photoshop once it's installed.//// Run:// * With Photoshop open, select File > Scripts > Create Icons// * When prompted select the prepared iTunesArtwork file for your app.// * The different version of the icons will get saved to the same folder that// the iTunesArtwork file is in.//// Adobe Photoshop JavaScript Reference// http://www.adobe.com/devnet/photoshop/scripting.html// Turn debugger on. 0 is off.// $.level = 1;try{ // Prompt user to select iTunesArtwork file. Clicking "Cancel" returns null. var iTunesArtwork = File.openDialog("Select a sqaure PNG file that is at least 1024x1024.", "*.png", false); if (iTunesArtwork !== null) { var doc = open(iTunesArtwork, OpenDocumentType.PNG); if (doc == null) { throw "Something is wrong with the file. Make sure it's a valid PNG file."; } var startState = doc.activeHistoryState; // save for undo var initialPrefs = app.preferences.rulerUnits; // will restore at end app.preferences.rulerUnits = Units.PIXELS; // use pixels if (doc.width != doc.height) { throw "Image is not square"; } else if ((doc.width < 1024) && (doc.height < 1024)) { throw "Image is too small! Image must be at least 1024x1024 pixels."; } else if (doc.width < 1024) { throw "Image width is too small! Image width must be at least 1024 pixels."; } else if (doc.height < 1024) { throw "Image height is too small! Image height must be at least 1024 pixels."; } // Folder selection dialog var destFolder = Folder.selectDialog( "Choose an output folder"); var outFolderIPad= new Folder(destFolder + "/Icons-iOS"); if (!outFolderIPad.exists) { outFolderIPad.create(); } var outFolderIPad= new Folder(destFolder + "/Icons-Android"); if (!outFolderIPad.exists) { outFolderIPad.create(); } if (destFolder == null) { // User canceled, just exit throw ""; } // Save icons in PNG using Save for Web. var sfw = new ExportOptionsSaveForWeb(); sfw.format = SaveDocumentType.PNG; sfw.PNG8 = false; // use PNG-24 sfw.transparency = false; doc.info = null; // delete metadata // iOS var icons = [ {"name": "iTunesArtwok@2x", "size":1024}, {"name": "iTunesArtwork", "size":512}, {"name": "iPhone Notification iOS 7-11 20@2x", "size":40}, {"name": "iPhone Notification iOS 7-11 20@3x", "size":60}, {"name": "iPhone Spotlight iOS Settings iOS 5-6 29", "size":29}, {"name": "iPhone Spotlight iOS Settings iOS 5-11 29@2x", "size":58}, {"name": "iPhone Spotlight iOS Settings iOS 5-11 29@3x", "size":87}, {"name": "iPhone Spotlight iOS 7-11 40@2x", "size":80}, {"name": "iPhone Spotlight iOS 7-11 40@3x", "size":120}, {"name": "iPhone Settings iOS 7-11 29@3x", "size":87}, {"name": "iPhone Settings iOS 7-11 29@2x", "size":58}, {"name": "iPhone Settings iOS 7-11 29@1x", "size":29}, {"name": "iPhone App iOS 5-6 57", "size":57}, {"name": "iPhone App iOS 5-6 57@2x", "size":114}, {"name": "iPhone App iOS 7-11 60@2x", "size":120}, {"name": "iPhone App iOS 7-11 60@3x", "size":180}, {"name": "App Store iOS 1024", "size":1024}, {"name": "iPad Notifications iOS 7-11 20", "size":20}, {"name": "iPad Notifications iOS 7-11 20@2x", "size":40}, {"name": "iPad Settings iOS 5-11 29", "size":29}, {"name": "iPad Settings iOS 5-11 29@2x", "size":58}, {"name": "iPad Spotlight iOS 7-11 40", "size":40}, {"name": "iPad Spotlight iOS 7-11 40@2x", "size":80}, {"name": "iPad Spotlight iOS 5,6 50", "size":50}, {"name": "iPad Spotlight iOS 5,6 50@2x", "size":100}, {"name": "iPad App iOS 5,6 72", "size":72}, {"name": "iPad App iOS 5,6 72@2x", "size":144}, {"name": "iPad App iOS 7-11 76", "size":76}, {"name": "iPad App iOS 7-11 76@2x", "size":152}, {"name": "iPad Pro App iOS 9-11 83.5pt@2x", "size":167} ]; var icon; for (i = 0; i < icons.length; i++) { icon = icons[i]; doc.resizeImage(icon.size, icon.size, // width, height null, ResampleMethod.BICUBICSHARPER); var destFileName = icon.name + ".png"; doc.exportDocument(new File(destFolder + "/Icons-iOS/" + destFileName), ExportType.SAVEFORWEB, sfw); doc.activeHistoryState = startState; // undo resize } sfw.transparency = true; // Android var icons = [ {"name": "Legacy_xxxhdpi_192", "size":192}, {"name": "Legacy_xxhdpi_144", "size":144}, {"name": "legacy_xhdpi_96", "size":96}, {"name": "Legacy_hdpi_72", "size":72}, {"name": "Legacy_mdpi_48", "size":48}, {"name": "Legacy_ldpi_36", "size":36}, {"name": "Round_xxxhdpi_192", "size":192}, {"name": "Round_xxhdpi_144", "size":144}, {"name": "Round_xhdpi_96", "size":96}, {"name": "Round_hdpi_72", "size":72}, {"name": "Round_mdpi_48", "size":48}, {"name": "Round_ldpi_26", "size":36}, {"name": "Adaptive_xxxhdpi_432", "size":432}, {"name": "Adaptive_xxhdpi_324", "size":324}, {"name": "Adaptive_xhdpi_216", "size":216}, {"name": "Adaptive_hdpi_162", "size":162}, {"name": "Adaptive_mdpi_108", "size":108}, {"name": "Adaptive_ldpi_81", "size":81} ]; var icon; for (i = 0; i < icons.length; i++) { icon = icons[i]; doc.resizeImage(icon.size, icon.size, // width, height null, ResampleMethod.BICUBICSHARPER); var destFileName = icon.name + ".png"; doc.exportDocument(new File(destFolder + "/Icons-Android/" + destFileName), ExportType.SAVEFORWEB, sfw); doc.activeHistoryState = startState; // undo resize } alert("Icons created!"); }}catch (exception){ // Show degbug message and then quit if ((exception != null) && (exception != "")) alert(exception); }finally{ if (doc != null) doc.close(SaveOptions.DONOTSAVECHANGES); app.preferences.rulerUnits = initialPrefs; // restore prefs}