Skip to content

Instantly share code, notes, and snippets.

@dominik-hadl
Created November 25, 2013 20:15
Show Gist options
  • Save dominik-hadl/7648076 to your computer and use it in GitHub Desktop.
Save dominik-hadl/7648076 to your computer and use it in GitHub Desktop.
This is a handy Photoshop script that creates all required and optional iPhone and iPad application icons, including the new dimensions introduced in iOS7. Install instructions are written in the bottom part of the header. Photoshop CS6 or CC is required to run this script. You will have to specify the PSD file containing your icon and then the …
/**
* Photoshop Script to Create iOS 7 Icons from a PSD file
* Version: 1.0.1 (November 2013)
*
* Copyright (c) 2013 Dominik Hadl (@dominikhadl)
*
* 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.
*
* Install:
* 1) Move or Copy this file to "/Applications/Adobe Photoshop CC/Presets/Scripts".
* 2) Restart Photoshop.
*
* Run:
* 1) With Photoshop open, select File > Scripts > Create iOS7 Icons From PSD.
* 2) When prompted select the PSD file containing your app icon.
* 3) The resized and renamed versions of the icon will be saved to the same folder.
* where the PSD file is. (It will overwrite files with matching names!)
*/
// Check for version first
versionCheck();
// Prompt user to select iTunesArtwork file.
var iTunesArtworkPSD = File.openDialog("Please select the PSD file you would like to use.");
if (iTunesArtworkPSD !== null)
{
// Get save location
var savePath = Folder.selectDialog("Please specify the folder where do you want to save the icons.");
if (savePath == null)
{
alert("No save location specified.");
throw("No save location specified.");
}
// Show an alert
alert("Please wait, your icons will now be created.");
// Open the file
var doc = open(iTunesArtworkPSD, OpenDocumentType.PHOTOSHOP);
// Setup photoshop
var startState = doc.activeHistoryState; // save for undo
var initialRUnits = app.preferences.rulerUnits;
var initialTUnits = app.preferences.typeUnits;
var initialDDialogs = app.displayDialogs;
// Change default settings
app.preferences.rulerUnits = Units.PIXELS; // Set ruler units to pixels
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO; // Turn off all dialogs
// Output setup
var exportType = ExportType.SAVEFORWEB;
var options = new ExportOptionsSaveForWeb(); // Create new export options
options.format = SaveDocumentType.PNG; // Save as PNG
options.PNG8 = false; // Use PNG-24
options.transparency = true; // No transparency
doc.info = null; // Delete metadata
// Names and sizes of the required and optional icons
var icons = [
{"name": "Icon-72", "size":72},
{"name": "Icon-72@2x", "size":144},
{"name": "Icon-76", "size":76},
{"name": "Icon-76@2x", "size":152},
{"name": "Icon-120", "size":120},
{"name": "Icon-iPad-Small", "size":29},
{"name": "Icon-iPad-Small@2x", "size":58},
{"name": "Icon-iPad-Spotlight-iOS7", "size":40},
{"name": "Icon-iPad-Spotlight-iOS7@2x", "size":80},
{"name": "Icon-iPad-Spotlight", "size":50},
{"name": "Icon-iPad-Spotlight@2x", "size":100},
{"name": "Icon-iPhone-Spotlight-iOS7@2x", "size":80},
{"name": "Icon-Small", "size":29},
{"name": "Icon-Small@2x", "size":58},
{"name": "Icon", "size":57},
{"name": "Icon@2x", "size":114},
{"name": "iTunesArtwork", "size":512},
{"name": "iTunesArtwork@2x", "size":1024}
];
// Set the default extension
var extension = ".png";
// Do the resizing!
for (i = 0; i < icons.length; i++)
{
var icon = icons[i]; // Get the next icon in the list
if (i >= (icons.length - 2))
{
// Remove extension for last two icons
extension = "";
}
var file = new File(savePath + "/" + icon.name + extension);
resizeAndScaleStyles(icon.size, icon.size); // Do the resizing
doc.exportDocument(file, exportType, options); // Save it
doc.activeHistoryState = startState; // Undo resize
}
// Close the document
doc.close(SaveOptions.DONOTSAVECHANGES); // Close opened document and don't save changes
// Restore setup
app.preferences.rulerUnits = initialRUnits; // Restore ruler units
app.preferences.typeUnits = initialTUnits; // Restore type units
app.preferences.displayDialogs = initialDDialogs; // Restore display dialogs
alert("Your icons were successfully."); // Notify the user
}
else
{
alert("No PSD file specified.");
throw("No PSD file specified.");
}
function versionCheck() {
var numberArray = version.split(".");
if ( numberArray[0] < 14 ) {
alert("You have to use at least Photoshop CC (14) for this script.");
throw("You have to use at least Photoshop CC (14) for this script.");
}
}
function resizeAndScaleStyles(newWidth, newHeight)
{
// Get image size
var idImgS = charIDToTypeID( "ImgS" );
var desc2 = new ActionDescriptor();
// Get Width and Height (+ pixels unit)
var idWdth = charIDToTypeID( "Wdth" );
var idHgth = charIDToTypeID( "Hgth" );
var idPxl = charIDToTypeID( "#Pxl" );
// Set the required width and height
desc2.putUnitDouble( idWdth, idPxl, newWidth);
desc2.putUnitDouble( idHgth, idPxl, newHeight);
// Scale styles also
var idscaleStyles = stringIDToTypeID( "scaleStyles" );
desc2.putBoolean( idscaleStyles, true );
// Constrain Proportions
var idCnsP = charIDToTypeID( "CnsP" );
desc2.putBoolean( idCnsP, true );
// Other settings
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idBcbc = charIDToTypeID( "Bcbc" );
desc2.putEnumerated( idIntr, idIntp, idBcbc );
// Do the resize
executeAction( idImgS, desc2, DialogModes.NO );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment