Not that I know of. And even if there were, that would only work with formats that use a fixed encoding/ compression that can be calculated inside a script. It would not work with e.g. JPEG, as the size fluctuates too much based on what is in the image and what compression settings are used. Even image conversion programs that offer such a feature only can use the value as an approximate desirable result, not an absolute in such cases...
The issue has been discussed repeatedly and a viable approach would be to have the Script write the file, check its size, overwtrite it with different settings if it’s too big, check again etc.
I think I saw a Script that did that but couldn’t locate it the last time I saw somebody asking about the issue.