Copy link to clipboard
Copied
In a folder, there are sub-folders that contain only PSD files. I want to save all these images in WebP at 75% quality.
Is there any way to batch-process this in Photoshop?
If I use python script to automate this, will I get the same quality at 75% as that is done by photoshop?
Copy link to clipboard
Copied
Start with the following links:
Copy link to clipboard
Copied
In my case only this script is working as expected "
/*
Batch Save As WebP.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-many-files-at-once-in-webp-for...
v1.0 - 14th March 2023, Stephen Marsh
*/
#target photoshop
// Optionally run a specified action
//var actionName = "Molten Lead"; // Action to run, change as needed
//var actionSet = "Default Actions"; // Action set to run, change as needed
// Ensure that version 2022 or later is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber);
// Fail
if (versionCheck < 23) {
alert("You must use Photoshop 2022 or later to save using native WebP format...");
// Pass
} else {
// Set the input and output folders
var inputFolder = Folder.selectDialog("Please select the input folder:");
var outputFolder = Folder.selectDialog("Please select the output folder:");
// Limit the input files, add or remove extensions as required
var fileList = inputFolder.getFiles(/\.(webp|tif|tiff|jpg|jpeg|psd|psb|png)$/i);
fileList.sort();
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Set the file processing counter
var fileCounter = 0;
// Process the input files
for (var i = 0; i < fileList.length; i++) {
var doc = open(fileList[i]);
// If the doc isn't in RGB mode
if (activeDocument.mode !== DocumentMode.RGB) {
// Convert to sRGB & 8 bpc
activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
// Run the optional action
//app.doAction(actionName, actionSet);
// Save as a copy and close
saveWebP("compressionLossy", 75, true, true, true, true);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Increment the file saving counter
fileCounter++;
// If the doc is in RGB mode
} else {
// Convert to sRGB & 8 bpc
//activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
// Run the optional action
//app.doAction(actionName, actionSet);
// Save as a copy and close
saveWebP("compressionLossy", 75, true, true, true, true);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Increment the file saving counter
fileCounter++;
}
};
app.displayDialogs = savedDisplayDialogs;
alert('Script completed!' + '\n' + fileCounter + ' files saved to:' + '\r' + outputFolder.fsName);
function saveWebP(compType, compValue, xmpData, exifData, psData, asCopy) {
/*
v1.1 - 12th March 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/saving-webp-image-by-script/td-p/1364...
*/
// Doc and path save variables
var WebPDocName = activeDocument.name.replace(/\.[^\.]+$/, ''); // Remove file extension
var WebPSavePath = outputFolder + "/" + WebPDocName + ".webp" // Change path as needed
var WebPFile = new File(WebPSavePath); // Create the file object
/*
// Check for existing file object
if (WebPFile.exists) {
// true = 'No' as default active button
if (!confirm("File exists, overwrite: Yes or No?", true))
// throw alert("Script cancelled!");
throw null;
}
*/
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
// Compression parameters = "compressionLossless" | "compressionLossy"
descriptor2.putEnumerated(s2t("compression"), s2t("WebPCompression"), s2t(compType)); // string variable
var WebPCompIsLossless = false; // set the default flag for compression
if (WebPCompIsLossless == false) {
// 0 (lowest lossy quality) - 100 (highest lossy quality)
descriptor2.putInteger(s2t("quality"), compValue); // number variable
}
// Metadata options
descriptor2.putBoolean(s2t("includeXMPData"), xmpData); // Boolean param moved to function call
descriptor2.putBoolean(s2t("includeEXIFData"), exifData); // Boolean param moved to function call
descriptor2.putBoolean(s2t("includePsExtras"), psData); // Boolean param moved to function call
// WebP format and save path
descriptor.putObject(s2t("as"), s2t("WebPFormat"), descriptor2);
descriptor.putPath(s2t("in"), WebPFile); // Save path variable
// Save As = false | Save As a Copy = true
descriptor.putBoolean(s2t("copy"), asCopy); // Boolean param moved to function call
// The extension
descriptor.putBoolean(s2t("lowerCase"), true);
// Execute the save
executeAction(s2t("save"), descriptor, DialogModes.NO); // Change NO to ALL for dialog
}
}"
But the problem with this is that I am getting very large webp files compare to what I get when I use photoshop at 75% quality. Can you guide how to fix it?
Also, will I be able to maintain folder structure after running it?
Copy link to clipboard
Copied
I get the same file size from the script (which uses lossy 75% all metadata as the default) vs. manually saving at lossy 75% all metadata.