Support resize with a target file/stream size, rather than dimensions #1305
-
A resize transform that targeted a maximum file size (possibly with dimension vs quality tradeoffs) would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm afraid that cannot be done; there's simply too many variables. Operations on images are performed on the uncompressed pixels laid out in memory. An encoded image is subject to the compression rules and constraints of the individual format. Say I resize two separate images to a given set of dimensions and encode them using the same image format and options. Unless those two images were identical you will result in two output images of different file size. You'd have to brute force, rinsing and repeating the resize + encoding operation over and over again. It's not efficient. Perhaps someone could build something nifty with machine learning that could make a best guess after training but that's well out of scope of the library. |
Beta Was this translation helpful? Give feedback.
I'm afraid that cannot be done; there's simply too many variables.
Operations on images are performed on the uncompressed pixels laid out in memory. An encoded image is subject to the compression rules and constraints of the individual format.
Say I resize two separate images to a given set of dimensions and encode them using the same image format and options. Unless those two images were identical you will result in two output images of different file size.
You'd have to brute force, rinsing and repeating the resize + encoding operation over and over again. It's not efficient.
Perhaps someone could build something nifty with machine learning that could make a best guess after training bu…