/* * optimizeMyImages for Adobe Photoshop * * This script will optimize all images in a given folder and save them to another (or the same) folder. * Optimization involves resizing, coversion to RGB mode, and saving as a JPEG * * @Copyright: (c) Mohammad Jangda (batmoo@gmail.com) * @License: MIT License (http://www.opensource.org/licenses/mit-license.php) * */ #target photoshop /* * Config: Change the following values to your desired settings * MAX_WIDTH: The maximum width (in pixels) allowed for optimized images * MAX_HEIGHT: The maximum height (in pixels) allowed for optimized images * FILE_TYPES: The allowed file types that should be optimized */ const MAX_WIDTH = 1600; const MAX_HEIGHT = 1200; var FILE_TYPES = [".jpg",".jpeg",".png",".tiff",".tif",".gif",".psd"]; /* * end config */ /* * begin script */ openFilePath = Folder.selectDialog ("Please select a folder to iterate though:"); saveFilePath = Folder.selectDialog ("Please select a folder to save the web-ready images to:"); openFolder = new Folder(openFilePath); saveFolder = new Folder(saveFilePath); iterate(openFolder, saveFolder); function iterate(openPath, savePath) { var files = openPath.getFiles(); var f; for (var i=0; i doc.height.as("px")) { doc.resizeImage(maxWidth); } else { ratio = doc.width.as("px") / doc.height.as("px"); width = maxHeight * ratio; doc.resizeImage(width,maxHeight); } } //ensure RGB mode if(doc.mode!="RGB") { doc.changeMode(ChangeMode.RGB); } // Save as JPEG jpgSaveOptions = new JPEGSaveOptions(); jpgSaveOptions.embedColorProfile = true; jpgSaveOptions.matte = MatteType.NONE; jpgSaveOptions.quality = 8; app.activeDocument.saveAs(savePath, jpgSaveOptions, false, Extension.LOWERCASE); } //Close all open images while (app.documents.length) { app.activeDocument.close(); } }