Can I set max-size instead of just size? (Only scale down)
See original GitHub issueFirst of all, really glad to see new Thumbnailator releases in 2020 after ~6 years of silence. Cheers!
I’d like to know if there is an option to restrict upscaling of images and only resize them down. We plan to use Thumbnailator as dynamic on-fly resizer rather than for making static thumbnails, so in rare circumstances original image may be smaller than requested size. What happens now is that image is scaled UP to requested size and becomes very messy. I haven’t found any method to tell Thumbnailator not to make images larger than they already are (even if requested size says so), only make them smaller. Is there such method?
Example:
Image original size is 150*150. For some internal reasons we call resize(200, 200)
.
I want result image to stay 150*150.
void resize(InputStream is, OutputStream os, int width, int height) {
Thumbnails.of(is).size(width, height).toOutputStream(os);
}
Consider this as CSS max-width
attribute instead of width
.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
One solution:
And then:
I’ve tried a
ResizerFactory
returning aNullResizer
without success, it still upscales the image.