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?

1 Answer 1

0

I believe the only way you can do this is to get the Content-Length value directly from the HTTP header. JS doesn't have access to the file's properties (other than size), as far as I know. Answered more thoroughly over here:

Determining image file size + dimensions via Javascript?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.