coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.08k stars 780 forks source link

How to make the image width fixed when the image is scaled #212

Closed epubreader closed 2 months ago

epubreader commented 7 months ago

How to make the width of the picture fixed and keep the original aspect ratio when the picture is scaled?

coobird commented 7 months ago

@epubreader, does the width method accomplish what you want to do?

Thumbnails.of("/path/to/image")
    .width(200)
    .toFile("/path/to/thumbnail");

In this example, the thumbnail will have a width of 200 pixels, while the height will be adjusted to maintain the aspect ratio of the original image.