in thumbnails4j-core/src/main/java/co/elastic/thumbnails4j/core/ThumbnailUtils.java [86:112]
public static BufferedImage scaleImage(BufferedImage image, Dimensions dimensions, int imageType){
int scaledWidth = image.getWidth();
int scaledHeight = image.getHeight();
double widthRatio = ((double)scaledWidth)/dimensions.getWidth();
double heightRatio = ((double) scaledHeight)/dimensions.getHeight();
double aspectRatio = Math.max(widthRatio, heightRatio);
int targetWidth = (int) Math.round(scaledWidth/aspectRatio);
int targetHeight = (int) Math.round(scaledHeight/aspectRatio);
// until we reach the desired width/height
while (scaledWidth != targetWidth || scaledHeight != targetHeight) {
scaledWidth = scaleDimension(scaledWidth, targetWidth);
scaledHeight = scaleDimension(scaledHeight, targetHeight);
// redraw the image with the new width/height for this iteration
BufferedImage temp = new BufferedImage(scaledWidth, scaledHeight, imageType);
Graphics2D graphics = temp.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);
graphics.dispose();
image = temp;
}
return image;
}