问题
I'm trying to utilize the following. what this does is saves out Jpeg accordingly to less then a a certain size set. I was curious if anyone knew a way to specifically direct a filename to get a filesize that is equal to the following or as close as possible.
Filename_160x600.png = Filename_160x600.jpg 39kb
Filename_300x600.png = Filename_300x600.jpg 59kb
Filename_1500x513.png = Filename_1500x513.jpg 150kb
saveJPG(
{
path: activeDocument.path,
maxSize: 50 //size in kbs
})
function saveJPG(_data)
{
if (_data.path == undefined) return false;
_data.name = _data.name == undefined ? activeDocument.name : _data.name;
_data.quality == undefined && _data.quality = 75;
if (!new Folder(_data.path).exists)
{
alert("Output path doesn't exist!"); //you can add a function to create a path if needed
return false
}
var options = new ExportOptionsSaveForWeb(),
jpgFile = new File(_data.path + '/' + getName(_data.name) + '.jpg');
options.format = SaveDocumentType.JPEG;
options.quality = _data.quality;
activeDocument.exportDocument(jpgFile, ExportType.SAVEFORWEB, options);
if (_data.maxSize != undefined)
{
var ms = _data.maxSize * 1000;
if (jpgFile.length > ms)
{
if (!jpgFile.remove())
{
alert('Save file is locked, please make sure it\'s not opened anywhere');
return
};
saveJPG(
{
path: _data.path,
name: _data.name,
maxSize: _data.maxSize,
quality: _data.quality - 2
});
}
};
来源:https://stackoverflow.com/questions/52341077/extendscript-photoshop-is-there-a-way-to-save-out-jpeg-with-specific-kb-file-si