Resizes an image so that the result has the specified height. The width will be variable, and depends on the aspect ratio of the initial image.
static RenderedImage resizeImageToHeight(source, height)
The new image’s height is guaranteed to be equal to the requested value. The width will be scaled by the same amount that the height was, and will vary depending on the source image’s aspect ratio. The following table contains example image dimensions, and what size image will be created by a call to this method.
| Original Size | Requested Width | New Size |
|---|---|---|
| 800×800 | 200 | 200×200 |
| 800×400 | 200 | 400×200 |
| 400×800 | 200 | 100×200 |
The following example shows how to load an image file, resize it to fit inside a 150 pixel tall row, and then save it as a new image:
import net.devella.thumbs.ThumbMaster;
...
// read source image from a file
RenderedImage source =
ImageIO.read(new File("/tmp/source.png"));
// resize the image
RenderedImage result =
ThumbMaster.resizeImageToHeight(source, 150);
// write the image to a new file
ImageIO.write(result, "png", new File("/tmp/result.png"));
...
© 2008 Sean Kleinjung. All Rights Reserved.