Skip to content

Instantly share code, notes, and snippets.

@pixelbacon
Last active August 29, 2015 14:27
Show Gist options
  • Save pixelbacon/d3cddcc540251320d4b7 to your computer and use it in GitHub Desktop.
Save pixelbacon/d3cddcc540251320d4b7 to your computer and use it in GitHub Desktop.

Export Folder of PSDs to JPEG

Simple script to run in Photoshop to be able to export an entire folder of PSD or AI files ot JPG0 Combined from other scripts.

Sources

// Source: https://gist.github.com/pixelbacon/7754cba64125b0240504
// Inspired by:
// https://github.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx
// http://blog.wp.weightpoint.se/2012/02/02/batch-export-photoshop-psd-files-to-png-the-right-way/
`
// To use open Script via Photoshop OR File > Scripts > Browse
#target "photoshop"
if (BridgeTalk.appName == "photoshop")
{
app.bringToFront;
var inputFolder = Folder.selectDialog("Select the folder that contains the files for export:");
var outputFolder = Folder.selectDialog("Select the folder to output to:");
if (inputFolder != null) {
var fileList = inputFolder.getFiles (/\.(psd|ai)$/i);
var maxPixels = prompt ("Maximum height & width for exported files:", "2000");
var desiredWidth = prompt ("Desired WIDTH for exported files:", maxPixels);
var desiredHeight = prompt ("Desired HEIGHT for exported files:", maxPixels);
for (var i = 0; i < fileList.length; i++) {
if (fileList [i] instanceof File) {
var document = open (fileList [i]);
var documentName = fileList [i].name.slice (0, -4);
while (app.documents.length) {
var newFile = new File (decodeURI (outputFolder) + "/" + documentName + ".jpg");
var max = maxPixels + " pixels";
document.flatten ();
if (document.resolution > 72 || (document.width > max || document.height > max)) {
if (document.width > document.height) {
var newWidth = new UnitValue (desiredWidth + " pixels");
var newHeight = new UnitValue (desiredHeight + " pixels");
} else {
var newWidth = new UnitValue (desiredHeight + " pixels");
var newHeight = new UnitValue (desiredWidth + " pixels");
}
document.resizeImage (newWidth, newHeight, 72);
}
exportOptions = new ExportOptionsSaveForWeb ();
exportOptions.format = SaveDocumentType.JPEG;
exportOptions.quality = 80;
document.exportDocument (newFile, ExportType.SAVEFORWEB, exportOptions);
document.close (SaveOptions.DONOTSAVECHANGES);
}
}
if (i == fileList.length - 1) {
alert ("All the files have been exported.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment