Created
February 15, 2018 14:38
-
-
Save Funi1234/eed23bfd4b64eca116dc9ac7c079e37e to your computer and use it in GitHub Desktop.
iOS App Icon Generator
This file contains hidden or 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
// Photoshop Script to Create iPhone App Icons from iTunesArtwork/1024px size image | |
// | |
// In the Event of name collisions this script will overwrite files in the export folder. | |
// | |
// MIT License | |
// | |
// Copyright (c) 2016 Dylan Conway | |
// | |
// 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. | |
// 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 requiredSize = 512 | |
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 < requiredSize) && (doc.height < requiredSize)) | |
{ | |
throw "Image is too small! Image must be at least 1024x1024 pixels."; | |
} | |
else if (doc.width < requiredSize) | |
{ | |
throw "Image width is too small! Image width must be at least 1024 pixels."; | |
} | |
else if (doc.height < requiredSize) | |
{ | |
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 | |
var icons = [ | |
{"name": "AppIcon20x20@2x", "size":40}, | |
{"name": "AppIcon20x20@3x", "size":60}, | |
//{"name": "AppIcon29", "size":29}, | |
{"name": "AppIcon29x29@2x", "size":58}, | |
{"name": "AppIcon29x29@3x", "size":87}, | |
{"name": "AppIcon40x40@2x", "size":80}, | |
{"name": "AppIcon40x40@3x", "size":120}, | |
//{"name": "AppIcon57x57", "size":57}, | |
//{"name": "AppIcon57x57@2x", "size":114}, | |
{"name": "AppIcon60x60@2x", "size":120}, | |
{"name": "AppIcon60x60@3x", "size":180}, | |
//{"name": "Icon-40", "size":40}, | |
//{"name": "Icon-76", "size":76}, | |
//{"name": "Icon-76@2x", "size":152}, | |
//{"name": "Icon-120", "size":120}, | |
//{"name": "iTunesArtwork", "size":512}, | |
{"name": "AppIcon1024x1024", "size":1024} | |
//{"name": "Icon", "size":57}, | |
//{"name": "Icon@2x", "size":114}, | |
//{"name": "Icon-72", "size":72}, | |
//{"name": "Icon-72@2x", "size":144}, | |
//{"name": "Icon-Small-50", "size":50}, | |
//{"name": "Icon-Small-50@2x", "size":100} | |
]; | |
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"; | |
if ((icon.name == "iTunesArtwork@2x") || (icon.name == "iTunesArtwork")) | |
{ | |
// iTunesArtwork files don't have an extension | |
destFileName = icon.name; | |
} | |
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