Created
November 30, 2013 19:11
-
-
Save iamMehedi/7723223 to your computer and use it in GitHub Desktop.
This is a Photoshop Script to create all versions of launcher icon needed for Android from a chosen source image file. This Gist is inspired from: https://gist.github.com/appsbynight/3681050
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prerequisite: | |
// First, create at least a 512x512 px PNG file | |
// Install - Save Create Android Icons.jsx to: | |
// Win: C:\Program Files\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\SDK | |
// Mac: /Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS6/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 Artwork file for your app. | |
// * The different version of the icons will get saved to the same folder that | |
// the Artwork 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 Artwork = File.openDialog("Select a sqaure PNG file that is at least 512x512.", "*.png", false); | |
if (Artwork !== null) | |
{ | |
var doc = open(Artwork, 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 < 512) && (doc.height < 512)) | |
{ | |
throw "Image is too small! Image must be at least 512x512 pixels."; | |
} | |
else if (doc.width < 512) | |
{ | |
throw "Image width is too small! Image width must be at least 512 pixels."; | |
} | |
else if (doc.height < 512) | |
{ | |
throw "Image height is too small! Image height must be at least 512 pixels."; | |
} | |
// Folder selection dialog | |
var destFolder = Folder.selectDialog( "Choose an output folder"); | |
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 = true; | |
doc.info = null; // delete metadata | |
var icons = [ | |
{"name": "ic_launcher_Web", "size":512}, | |
{"name": "ic_launcher_xxxhdpi", "size":192}, | |
{"name": "ic_launcher_xxhdpi", "size":144}, | |
{"name": "ic_launcher_xhdpi", "size":96}, | |
{"name": "ic_launcher_hdpi", "size":72}, | |
{"name": "ic_launcher_mdpi", "size":48}, | |
{"name": "ic_launcher_ldpi", "size":36} | |
]; | |
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 + "/" + destFileName), ExportType.SAVEFORWEB, sfw); | |
doc.activeHistoryState = startState; // undo resize | |
} | |
alert("Android Launcher 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment