When I export a PSD file to a JPG using the Photoshop client, the file size is only a few tens of kilobytes when the quality is set to 7. However, when I use ExtendScript's SaveAs function, the resulting file size is around 3-4 megabytes. Even when dynamically adjusting the quality parameter, the reduction in size is very limited. Below is my code, please help me find a solution.
finalPsdFile = new File(folder + "/" + imageName + "/" + makeName + "/" + outName + ".psd");
docRef = app.open(finalPsdFile);
var jpgFile = new File(folder + "/" + imageName + "/" + makeName + "/" + outName + ".jpg");
var jpgOptions = new JPEGSaveOptions();
jpgOptions.matte = MatteType.NONE;
jpgOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgOptions.embedColorProfile = true;
quality = 12
jpgOptions.quality = quality;
docRef.saveAs(jpgFile, jpgOptions, true, Extension.LOWERCASE);
var maxFileSize = makeData["maxSize"];
while (maxFileSize > 0 && jpgFile.length > maxFileSize * 1024 && quality > 0) {
quality -= 1;
jpgOptions.quality = quality;
docRef.saveAs(jpgFile, jpgOptions, true, Extension.LOWERCASE);
jpgFile.close();
jpgFile = new File(folder + "/" + imageName + "/" + makeName + "/" + outName + ".jpg");
}
docRef.close(SaveOptions.DONOTSAVECHANGES);