-
Notifications
You must be signed in to change notification settings - Fork 6
/
Automated Resize To Web.jsx
61 lines (51 loc) · 2.95 KB
/
Automated Resize To Web.jsx
1
/* * @title Automated Resize to Web * @desc This is a script for Photoshop that batch processes on all supported filetypes (jpg, jpeg, tif, psd) in the chosen directory * to be web ready. The script outputs the new files to the .jpg filetype. The only saving method is "Save for Web...", there is * no print quality exporting with this script. The accepted filetypes: jpg, jpeg, tif, psd. * * @author Jonah Bitautas, http://workfunc.com */#target "photoshop"if (BridgeTalk.appName == "photoshop") { app.bringToFront; var inputFolder = Folder.selectDialog ("Select the folder that contains the files for export:"); if (inputFolder != null) { var fileList = inputFolder.getFiles (/\.(jpg|jpeg|tif|psd|)$/i); var outputFolder = new Folder (decodeURI (inputFolder) + "/Edited"); var maxPixels = prompt ("Please choose the MAXIMUM for exported files:", "700"); var desiredWidth = prompt ("Please choose the desired WIDTH for exported files. This must be less than the maximum:", "640"); var desiredHeight = prompt ("Please choose the desired HEIGHT for exported files. This must be less than the maximum:", "480"); if (outputFolder.exists == false) outputFolder.create (); 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."); } } }}