Copy link to clipboard
Copied
Hello,
I have a question about webp format in photoshop. I want to export many files at once in webp format in Photoshop but I don't find the webp format in photoshop options. Is it normal?
Best regards
WebP was introduced in Ps2022 as a native Save As (a Copy) option, not under Export As/Quick Export. You will either need to set up a batch action to save directly to WebP or to convert from PNG to WebP or use a custom script to save or convert to WebP.
In previous versions, there were 3rd party plugins from Google or other developers.
Here is a batch script to save as WebP.
Features:
* Optionally run an action (edit the code to enable)
* Optionally ask to overwrite existing files (edit the code to enable)
* Set an input and output folder
* Set supported input file types (edit the code)
* Automatically converts non-RGB mode to sRGB space, 8 bpc
* RGB files automatically converted to 8 bpc
* Option to convert RGB mode to sRGB space (edit the code to enable)
* WebP lossy format, 75% quality (larger size), all metadata and PSD
...Copy link to clipboard
Copied
If I do this as a batch action theres no way to set the images for example to be about 50kb upon output is there? The images in my folder that are to be convered range from 90kb to 20mb
By @melajuana
Not with this code.
To hit a target size on drive, the script would need to save, check the size and resave multiple times with decreasing quality levels to try to hit the target. This is certainly possible, however, it's obviously time consuming.
Copy link to clipboard
Copied
So much variables this depends on. First try to make test saves, don't save with extra data options. So no extras, no xnpndata etc. find the correct file size. Than it very much depends per image. The more color data is in your image, the heavier it is. By this I mean. When there are many colors and tints and hues, an image tends to be bigger
Copy link to clipboard
Copied
Your script has been a gift. Thank you @Stephen_A_Marsh .
I have browse almost all the threads about it and didn´t find how could I change the output resolution. Is that possible?
Copy link to clipboard
Copied
Use a script to resize it or use fit command. You can simple record an action for this and than run this script. That's not so hard to make your self. No need for a custom build script for such a small thing
Copy link to clipboard
Copied
Yes, my batch script does offer an option to run a user defined action set/action to provide additional processing without requiring extra code.
Copy link to clipboard
Copied
I've tried, but it seems I can´t make it work. Code is not my thing.
PS stops at the first image without even performing the action.
Copy link to clipboard
Copied
Please clarify which of the following are required:
1) Resize the image, resampling to a desired target size on the longest edge, such as 1920px
2) As #1 but also setting a specific print metadata resolution value such as 300ppi
3) Resize to a target PPI such as 300ppi, without resampling the image pixels
Copy link to clipboard
Copied
@Stephen_A_Marsh Option 2. Thank you.
Copy link to clipboard
Copied
The following changes to the script from page 2 of this thread will fit the image to 1920px on the longest edge, proportionally scaling the short edge and also setting the resolution metadata at 300ppi.
/*
Batch Save As WebP.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-many-files-at-once-in-webp-format-photoshop/m-p/13604411
v1.0 - 14th March 2023, Stephen Marsh
v1.1 - 11th January 2024: Added a "fit image" to 1920px step
v1.2 - 10th February 2024: Added an explicit step to change to RGB mode for non-RGB images
*/
#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.changeMode(ChangeMode.RGB);
activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
// Run the optional action
//app.doAction(actionName, actionSet);
// Fit image to 1920px
fitImage(1920, 1920);
// 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);
// Fit image to 1920px
fitImage(1920, 1920);
// Save as a copy and close
saveWebP("compressionLossy", 75, true, true, true, true);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Increment the file saving counter
fileCounter++;
}
};
/* NEARESTNEIGHBOR | BILINEAR | BICUBIC | BICUBICSMOOTHER | BICUBICSHARPER | BICUBICAUTOMATIC */
function fitImage(fWidth, fHeight) {
if (activeDocument.height.value > activeDocument.width.value) {
activeDocument.resizeImage(null, UnitValue(fHeight, "px"), 300, ResampleMethod.BICUBIC);
} else {
activeDocument.resizeImage(UnitValue(fWidth, "px"), null, 300, ResampleMethod.BICUBIC);
}
}
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/13642577
*/
// 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
}
}
Copy link to clipboard
Copied
I know. That's what I've been using, but I can´t choose the dpi output just like I set the image size or the compression rate. I'm asking precisely because I need a resolution lower than 300 dpi, images are going to be displayed only in digital devices.
Copy link to clipboard
Copied
I know. That's what I've been using, but I can´t choose the dpi output just like I set the image size or the compression rate. I'm asking precisely because I need a resolution lower than 300 dpi, images are going to be displayed only in digital devices.
By @carmen_maría_9071
The longest edge is 1920px, set by the code here:
// Fit image to 1920px
fitImage(1920, 1920);
This is the size regardless of the PPI print metadata value.
To change the PPI metadata, just change the following 2 instances of 300 to whatever you want, 72 or 96 etc.
/* NEARESTNEIGHBOR | BILINEAR | BICUBIC | BICUBICSMOOTHER | BICUBICSHARPER | BICUBICAUTOMATIC */
function fitImage(fWidth, fHeight) {
if (activeDocument.height.value > activeDocument.width.value) {
activeDocument.resizeImage(null, UnitValue(fHeight, "px"), 300, ResampleMethod.BICUBIC);
} else {
activeDocument.resizeImage(UnitValue(fWidth, "px"), null, 300, ResampleMethod.BICUBIC);
}
}
Keep in mind that the resolution metadata value has no impact on the pixel values of the longest edge.
Copy link to clipboard
Copied
Thank you!