Created
February 24, 2015 11:28
-
-
Save ailinykh/7619cf542996cecda9d0 to your computer and use it in GitHub Desktop.
Photoshop script to resize images for iOS app
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
try { | |
doc = app.activeDocument; | |
if (doc == null) | |
{ | |
throw "Something is wrong with the current active document. Make sure it's a valid PSD file."; | |
} | |
var fileName = prompt("Enter file name please", doc.name); | |
// Trim all pransparent pixels | |
doc.trim(TrimType.TRANSPARENT); | |
// Save as 2x | |
var sfw = new ExportOptionsSaveForWeb(); | |
sfw.format = SaveDocumentType.PNG; | |
sfw.PNG8 = false; // use PNG-24 | |
sfw.transparency = true; | |
doc.info = null; // delete metadata | |
var destFileName = fileName + "@2x.png"; | |
doc.exportDocument(new File("~/Desktop/" + destFileName), ExportType.SAVEFORWEB, sfw); | |
// Resize to 1x | |
doc.resizeImage(doc.width/2, doc.height/2); | |
destFileName = fileName + ".png"; | |
doc.exportDocument(new File("~/Desktop/" + destFileName), ExportType.SAVEFORWEB, sfw); | |
doc.close(SaveOptions.DONOTSAVECHANGES); | |
} catch (exception) { | |
if ((exception != null) && (exception != "")) | |
alert(exception); | |
} finally { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment