0

There are number of images.
The task is: resize every image to 2000px and it should be less than 500kb.
Current script (.jsx) resize images (app.activeDocument.resizeImage), but some of resized images bigger 500kb (save for web: for quality 81).
So the idea is to loop: check size of current image, if size>500, decrement quality to 80, check size and so on...

Some lines of code are:

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
...
var desc1 = new ActionDescriptor(); var desc2 = new ActionDescriptor();
...
desc2.putEnumerated(cTID('Fmt '), cTID('IRFm'), sTID("JPEGFormat"));
...
desc2.putInteger(cTID('Qlty'), 81);
...
desc2.putPath(cTID('In  '), new File("/c/folder"));
desc1.putObject(cTID('Usng'), sTID("SaveForWeb"), desc2);
executeAction(cTID('Expr'), desc1, dialogMode);
  1. JavaScript in browser has no access to user's drive. So what about the jsx in Photoshop, looks like it's the same?
  2. Is it any way to check the size of the jpeg image what will be saved (with current quality) through cTID?
4

1 回答 1

0

我相信您可以做到这一点的唯一方法是直接从 HTTP 标头获取 Content-Length 值。据我所知,JS 无权访问文件的属性(大小除外)。在这里更彻底地回答:

通过Javascript确定图像文件大小+尺寸?

于 2015-10-22T21:46:36.803 回答