Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Unity Icons Generator for Win Store, Android & iOS Photoshop Script
// Based on https://gist.github.com/appsbynight/3681050 by Matt Di Pasquale
// Author: Victor Corvalan
// http://twitter.com/pescadon
// This script will generate squares and wide Icons & Tiles required for Windows Store build on Unity3D
// Prepare 1 big icon of 512x512px
// Open this script with Photoshop -> File -> Scripts -> Browse
// Load your icon when prompted
var destFolder;
try
{
var bigIcon = File.openDialog("Select a square PNG file that is at least 512x512.", "*.png", false);
if (bigIcon !== null)
{
var doc = open(bigIcon, OpenDocumentType.PNG);
if (doc == null)
{
throw "Something is wrong with the file. Make sure it's a valid PNG file.";
}
var startState = doc.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.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
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 = [
{"folder":"Icons","name": "icon192", "size":192},
{"folder":"Icons","name": "icon144", "size":144},
{"folder":"Icons","name": "icon96", "size":96},
{"folder":"Icons","name": "icon72", "size":72},
{"folder":"Icons","name": "icon48", "size":48},
{"folder":"Icons","name": "icon36", "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";
var folder = Folder(destFolder+"/"+icon.folder);
if(!folder.exists) folder.create();
doc.exportDocument(new File(destFolder + "/" + icon.folder + "/" + 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;
}
// Based on https://gist.github.com/appsbynight/3681050 by Matt Di Pasquale
// Author: Victor Corvalan
// http://twitter.com/pescadon
// This script will generate squares and wide Icons & Tiles required for Windows Store build on Unity3D
// Prepare 1 big icon of 512x512px
// Open this script with Photoshop -> File -> Scripts -> Browse
// Load your icon when prompted
var destFolder;
try
{
var bigIcon = File.openDialog("Select a square PNG file that is at least 512x512.", "*.png", false);
if (bigIcon !== null)
{
var doc = open(bigIcon, OpenDocumentType.PNG);
if (doc == null)
{
throw "Something is wrong with the file. Make sure it's a valid PNG file.";
}
var startState = doc.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.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
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 = [
{"folder":"Icons","name": "icon180", "size":180},
{"folder":"Icons","name": "icon167", "size":167},
{"folder":"Icons","name": "icon152", "size":152},
{"folder":"Icons","name": "icon144", "size":144},
{"folder":"Icons","name": "icon120", "size":120},
{"folder":"Icons","name": "icon114", "size":114},
{"folder":"Icons","name": "icon76", "size":76},
{"folder":"Icons","name": "icon72", "size":72},
{"folder":"Icons","name": "icon57", "size":57}
];
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";
var folder = Folder(destFolder+"/"+icon.folder);
if(!folder.exists) folder.create();
doc.exportDocument(new File(destFolder + "/" + icon.folder + "/" + 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;
}
// Based on https://gist.github.com/appsbynight/3681050 by Matt Di Pasquale
// Author: Victor Corvalan
// http://twitter.com/pescadon
// This script will generate squares and wide Icons & Tiles required for Windows Store build on Unity3D
// Prepare 1 big icon of 1240x1240px
// Prepare 1 big wide icon of 1240x600px
// Open this script with Photoshop -> File -> Scripts -> Browse
// Load the images when prompted
var destFolder;
try
{
var bigIcon = File.openDialog("Select a square PNG file that is at least 1240x1240.", "*.png", false);
if (bigIcon !== null)
{
var doc = open(bigIcon, OpenDocumentType.PNG);
if (doc == null)
{
throw "Something is wrong with the file. Make sure it's a valid PNG file.";
}
var startState = doc.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (doc.width != doc.height)
{
throw "Image is not square";
}
else if ((doc.width < 1240) && (doc.height < 1240))
{
throw "Image is too small! Image must be at least 1240x1240 pixels.";
}
else if (doc.width < 1240)
{
throw "Image width is too small! Image width must be at least 1240 pixels.";
}
else if (doc.height < 1240)
{
throw "Image height is too small! Image height must be at least 1240 pixels.";
}
// Folder selection dialog
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 = [
{"folder":"Universal10/Square44x44","name": "icon256", "size":256},
{"folder":"Universal10/Square44x44","name": "icon48", "size":48},
{"folder":"Universal10/Square44x44","name": "icon24", "size":24},
{"folder":"Universal10/Square44x44","name": "icon16", "size":16},
{"folder":"Universal10/Square44x44","name": "icon176", "size":176},
{"folder":"Universal10/Square44x44","name": "icon88", "size":88},
{"folder":"Universal10/Square44x44","name": "icon66", "size":66},
{"folder":"Universal10/Square44x44","name": "icon55", "size":55},
{"folder":"Universal10/Square44x44","name": "icon44", "size":44},
{"folder":"Universal10/Square71x71","name": "icon71", "size":71},
{"folder":"Universal10/Square71x71","name": "icon89", "size":89},
{"folder":"Universal10/Square71x71","name": "icon107", "size":107},
{"folder":"Universal10/Square71x71","name": "icon142", "size":142},
{"folder":"Universal10/Square71x71","name": "icon284", "size":284},
{"folder":"Universal10/Square150x150","name": "icon150", "size":150},
{"folder":"Universal10/Square150x150","name": "icon188", "size":188},
{"folder":"Universal10/Square150x150","name": "icon225", "size":225},
{"folder":"Universal10/Square150x150","name": "icon300", "size":300},
{"folder":"Universal10/Square150x150","name": "icon600", "size":600},
{"folder":"Universal10/Square310x310","name": "icon310", "size":310},
{"folder":"Universal10/Square310x310","name": "icon388", "size":388},
{"folder":"Universal10/Square310x310","name": "icon465", "size":465},
{"folder":"Universal10/Square310x310","name": "icon620", "size":620},
{"folder":"Universal10/Square310x310","name": "icon1240", "size":1240},
{"folder":"WinPhone/Application Icon","name": "icon44", "size":44},
{"folder":"WinPhone/Application Icon","name": "icon62", "size":62},
{"folder":"WinPhone/Application Icon","name": "icon106", "size":106},
{"folder":"WinPhone/Small Tile","name": "icon71", "size":71},
{"folder":"WinPhone/Small Tile","name": "icon99", "size":99},
{"folder":"WinPhone/Small Tile","name": "icon170", "size":170},
{"folder":"WinPhone/Medium Tile","name": "icon150", "size":150},
{"folder":"WinPhone/Medium Tile","name": "icon210", "size":210},
{"folder":"WinPhone/Medium Tile","name": "icon360", "size":360},
{"folder":"Win/Small Logo","name": "icon24", "size":24},
{"folder":"Win/Small Logo","name": "icon30", "size":30},
{"folder":"Win/Small Logo","name": "icon42", "size":42},
{"folder":"Win/Small Logo","name": "icon54", "size":54},
{"folder":"Win/Medium Tile","name": "icon120", "size":120},
{"folder":"Win/Medium Tile","name": "icon150", "size":150},
{"folder":"Win/Medium Tile","name": "icon210", "size":210},
{"folder":"Win/Medium Tile","name": "icon270", "size":270},
{"folder":"Win/Small Tile","name": "icon56", "size":56},
{"folder":"Win/Small Tile","name": "icon70", "size":70},
{"folder":"Win/Small Tile","name": "icon98", "size":98},
{"folder":"Win/Small Tile","name": "icon126", "size":126},
{"folder":"Win/Large Tile","name": "icon248", "size":248},
{"folder":"Win/Large Tile","name": "icon310", "size":310},
{"folder":"Win/Large Tile","name": "icon434", "size":434},
{"folder":"Win/Large Tile","name": "icon558", "size":558},
{"folder":"Icon/Store Logo","name": "icon50", "size":50},
{"folder":"Icon/Store Logo","name": "icon63", "size":63},
{"folder":"Icon/Store Logo","name": "icon70", "size":70},
{"folder":"Icon/Store Logo","name": "icon75", "size":75},
{"folder":"Icon/Store Logo","name": "icon90", "size":90},
{"folder":"Icon/Store Logo","name": "icon100", "size":100},
{"folder":"Icon/Store Logo","name": "icon120", "size":120},
{"folder":"Icon/Store Logo","name": "icon200", "size":200}
];
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";
var folder = Folder(destFolder+"/"+icon.folder);
if(!folder.exists) folder.create();
doc.exportDocument(new File(destFolder + "/" + icon.folder + "/" + 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;
}
try
{
var wideIcon = File.openDialog("Select a PNG file of 1240x600 pixels.", "*.png", false);
if (wideIcon !== null)
{
var docWide = open(wideIcon, OpenDocumentType.PNG);
if (docWide == null)
{
throw "Something is wrong with the file. Make sure it's a valid PNG file.";
}
var startState = docWide.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if(docWide.width != 1240 && docWide.height != 600)
{
throw "Your PNG file is not 1240x600 pixels.";
}
// 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;
docWide.info = null;
var iconsWide = [
{"folder":"Universal10/Wide 310x150 Logo","name": "icon310x150", "w":310,"h":150},
{"folder":"Universal10/Wide 310x150 Logo","name": "icon388x188", "w":388,"h":188},
{"folder":"Universal10/Wide 310x150 Logo","name": "icon465x225", "w":465,"h":225},
{"folder":"Universal10/Wide 310x150 Logo","name": "icon620x300", "w":620,"h":300},
{"folder":"Universal10/Wide 310x150 Logo","name": "icon1240x600", "w":1240,"h":600},
{"folder":"WinPhone/Wide Tile","name": "icon310x150", "w":310,"h":150},
{"folder":"WinPhone/Wide Tile","name": "icon434x210", "w":434,"h":210},
{"folder":"WinPhone/Wide Tile","name": "icon744x360", "w":744,"h":360},
{"folder":"Win/Wide Tile","name": "icon248x120", "w":248,"h":120},
{"folder":"Win/Wide Tile","name": "icon310x150", "w":310,"h":150},
{"folder":"Win/Wide Tile","name": "icon434x210", "w":434,"h":210},
{"folder":"Win/Wide Tile","name": "icon558x270", "w":558,"h":270}
]
var iconWide;
for (i = 0; i < iconsWide.length; i++)
{
iconWide = iconsWide[i];
docWide.resizeImage(iconWide.w, iconWide.h, // width, height
null, ResampleMethod.BICUBICSHARPER);
var destFileName = iconWide.name + ".png";
var folder = Folder(destFolder+"/"+iconWide.folder);
if(!folder.exists) folder.create();
docWide.exportDocument(new File(destFolder + "/" + iconWide.folder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
docWide.activeHistoryState = startState; // undo resize
}
alert("Tiles created!");
}
}
catch (exception)
{
// Show degbug message and then quit
if ((exception != null) && (exception != ""))
alert(exception);
}
finally
{
if (docWide != null)
{
docWide.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