-
-
Save Johannestegner/f0e905b69048fa3c786d to your computer and use it in GitHub Desktop.
Photoshop script that generates Icons for Android and iOS devices.
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
/** | |
* Small script to generate icons for Android and iOS -devices. | |
* | |
* Copyrights: | |
* Copyright (c) 2010 Matt Di Pasquale (https://gist.github.com/mattdipasquale/711203) | |
* Added tweaks Copyright (c) 2012 by Josh Jones http://www.appsbynight.com (https://gist.github.com/appsbynight/3681050) | |
* Code cleanup, rewrite, minor buggfixing, addition of android icons and generation of the folders by Johannes Tegnér http://jite.eu | |
* | |
* 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. | |
* | |
*/ | |
var iconList = [ | |
{"folder": "iOS", "name": "", "size":29}, | |
{"folder": "android", "name": "", "size":29}, | |
{"folder": "iOS", "name": "icon-Small", "size":29}, | |
{"folder": "iOS", "name": "icon-Small@2x", "size":58}, | |
{"folder": "iOS", "name": "icon-Small@3x", "size":87}, | |
{"folder": "iOS", "name": "icon-Small-40", "size":40}, | |
{"folder": "iOS", "name": "icon-Small-40@2x", "size":80}, | |
{"folder": "iOS", "name": "Icon-60@2x", "size":120}, | |
{"folder": "iOS", "name": "Icon-76", "size":76}, | |
{"folder": "iOS", "name": "Icon-76@2x", "size":152}, | |
{"folder": "iOS", "name": "Icon-76@3x", "size":180}, | |
{"folder": "iOS", "name": "Icon-72", "size":72}, | |
{"folder": "iOS", "name": "Icon-72@2x", "size":144}, | |
{"folder": "iOS", "name": "Icon", "size":57}, | |
{"folder": "iOS", "name": "Icon-50", "size":50}, | |
{"folder": "iOS", "name": "Icon-50@2x", "size":100}, | |
{"folder": "iOS", "name": "iTunesArtwork", "size": 512}, | |
{"folder": "iOS", "name": "iTunesArtwork@2x", "size": 1024}, | |
{"folder": "android/drawable-mdpi", "name": "icon", "size": 48}, | |
{"folder": "android/drawable-hdpi", "name": "icon", "size": 72}, | |
{"folder": "android/drawable-xhdpi", "name": "icon", "size": 96}, | |
{"folder": "android/drawable-xxhdpi", "name": "icon", "size": 144} | |
]; | |
try { | |
var baseFile = File.openDialog("Please select a 1024x1024 (or larger) png file.", "*.png"); | |
if(baseFile) { | |
var image = open(baseFile, OpenDocumentType.PNG); | |
if(!image) { | |
throw "Failed to open image."; | |
} | |
var state = image.activeHistoryState; | |
preferences.rulerUnits = Units.PIXELS; | |
if(image.width != image.height || image.width < 1024 || image.height < 1024) { | |
throw "Wrong dimentions. Image should be at least 1024x1024 and width and height has to be the same.."; | |
} | |
var destFolder = Folder.selectDialog("Select output folder."); | |
if(!destFolder) { | |
throw "No folder selected."; | |
} | |
for(var i=0;i<iconList.length;i++) { | |
if(iconList[i].folder != "") { | |
var tempFolder = new Folder(destFolder + "/" + iconList[i].folder); | |
if(!tempFolder.exists) { | |
tempFolder.create(); | |
} | |
} | |
} | |
var saveForWeb = new ExportOptionsSaveForWeb(); | |
saveForWeb.format = SaveDocumentType.PNG; | |
saveForWeb.PNG8 = false; | |
saveForWeb.transparency = true; | |
var icon; | |
for(var i=0;i<iconList.length;i++) { | |
if(iconList[i].name === "") { | |
continue; | |
} | |
icon = iconList[i]; | |
image.resizeImage(icon.size, icon.size, null, ResampleMethod.BICUBICSHARPER); | |
var destinationFile = icon.name + ".png"; | |
if (icon.name == "iTunesArtwork@2x" || icon.name == "iTunesArtwork") { | |
destinationFile = icon.name; | |
} | |
image.exportDocument(new File(destFolder + "/" + icon.folder + "/" + destinationFile), ExportType.SAVEFORWEB, saveForWeb); | |
image.activeHistoryState = state; | |
} | |
image.close(SaveOptions.DONOTSAVECHANGES); | |
alert("Done!"); | |
} else { | |
throw "Sorry, for some reason the file could not be opened."; | |
} | |
} catch(ex) { | |
alert(ex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment