Skip to content

Instantly share code, notes, and snippets.

@ailinykh
Created February 24, 2015 11:28
Show Gist options
  • Save ailinykh/7619cf542996cecda9d0 to your computer and use it in GitHub Desktop.
Save ailinykh/7619cf542996cecda9d0 to your computer and use it in GitHub Desktop.
Photoshop script to resize images for iOS app
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