Skip to content

Instantly share code, notes, and snippets.

@UmberFunk
Forked from ma11hew28/Create Icons.jsx
Last active April 8, 2016 23:27
Show Gist options
  • Select an option

  • Save UmberFunk/916564596441e5b3bb8bd95faa036020 to your computer and use it in GitHub Desktop.

Select an option

Save UmberFunk/916564596441e5b3bb8bd95faa036020 to your computer and use it in GitHub Desktop.
Photoshop Script to Create iPhone and Android Icons from PNG. Updated with latest (04.2016) requirements and added second type of naming scheme.
// Photoshop Script to Create iPhone Icons from your PNG
//
// WARNING!!! In the rare case that there are name collisions, this script will
// overwrite (delete perminently) files in the same folder in which the selected
// PNG file is located. Therefore, to be safe, before running the
// script, it's best to make sure the selected PNG file is the only
// file in its containing folder.
//
// Copyright (c) 2010 Matt Di Pasquale
// Added tweaks Copyright (c) 2016 Irakli Geleishvili. http://bonsters.co
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Prerequisite:
// First, create at least a 1024x1024 px PNG file.
//
// Install - Save Create iOS Icons.jsx to:
// Win: C:\Program Files\Adobe\Adobe Photoshop CC 2015\Presets\Scripts
// Mac:
// * Restart Photoshop
//
// Update:
// * Just modify & save, no need to resart Photoshop once it's installed.
//
// Run:
// * With Photoshop open, select File > Scripts > Create iOS Icons
// * When prompted select the prepared PNG file for your app.
// * Select the destination folder.
// * The different version of the icons will get saved to the destination folder.
//
// 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 PNG file. Clicking "Cancel" returns null.
var PNG = File.openDialog("Select a sqaure PNG file that is at least 1024x1024.", "*.png", false);
if (PNG !== null)
{
var doc = open(PNG, 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");
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
// Naming scheme 1
/*
var icons = [
// https://developer.apple.com/library/ios/qa/qa1686/_index.html
// All this icons are for iPhone + iPad
{"name":"iTunesArtwork", "size":512}, // Ad Hoc only. Do not include in store release.
{"name":"iTunesArtwork@2x", "size":1024}, // Ad Hoc only. Do not include in store release.
// iOS later than 6.1
{"name":"Icon-60@2x.png", "size":120},
{"name":"Icon-60@3x.png", "size":180},
{"name":"Icon-76.png", "size":76}, // Required
{"name":"Icon-76@2x.png", "size":152},
{"name":"Icon-Small-40.png", "size":40},
{"name":"Icon-Small-40@2x.png", "size":80},
{"name":"Icon-Small-40@3x.png", "size":120}, // Required
{"name":"Icon-Small.png", "size":29}, //Recommended if you have a Settings bundle, optional otherwise
{"name":"Icon-Small@2x.png", "size":58}, //Recommended if you have a Settings bundle, optional otherwise
{"name":"Icon-Small@3x.png", "size":87}, //Recommended if you have a Settings bundle, optional otherwise
// Needed for iOS 6.1 or earlier
{"name":"Icon.png", "size":57},
{"name":"Icon@2x.png", "size":114},
{"name":"Icon-72.png", "size":72},
{"name":"Icon-72@2x.png" "size":144},
{"name":"Icon-Small-50.png", "size":50},
{"name":"Icon-Small-50@2x.png", "size":100},
// https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html
{"name":"icon60.png", "size":60},
{"name":"icon167.png", "size":167}
];
*/
// Naming scheme 2
var icons = [
{"size":29},
{"size":40},
{"size":48},
//{"size":50}, // iOS 6.1 or earlier
//{"size":57}, // iOS 6.1 or earlier
{"size":58},
{"size":60},
//{"size":72}, // iOS 6.1 or earlier
{"size":76}, // Required
{"size":80},
{"size":87},
//{"size":100}, // iOS 6.1 or earlier
//{"size":114}, // iOS 6.1 or earlier
{"size":120}, // Required
//{"size":144}, // iOS 6.1 or earlier
{"size":152},
{"size":167},
{"size":180},
{"size":512}, // Ad Hoc only. Do not include in store release.
{"size":1024} // Ad Hoc only. Do not include in store release.
];
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; // Uncomment if you want to use naming scheme 1
var destFileName = "ICON_" + icon.size + ".png"; // Comment if you want to use naming scheme 1
doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
doc.activeHistoryState = startState; // undo resize
}
alert("iOS 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