in thumbnails4j-core/src/main/java/co/elastic/thumbnails4j/core/ThumbnailUtils.java [180:189]
public static BufferedImage scaleHtmlToImage(byte[] htmlBytes, Dimensions dimensions) throws UnsupportedEncodingException {
JEditorPane htmlComponent = new JEditorPane("text/html", new String(htmlBytes, StandardCharsets.UTF_8));
Dimension preferredSize = htmlComponent.getPreferredSize();
int width = preferredSize.width;
double ratio = ((double) width) / dimensions.getWidth(); // determine the ratio between the actual width and the expected width
int height = (int) (ratio * dimensions.getHeight()); // use that ratio to set the height (ignoring actual height)
htmlComponent.setSize(width, height); // this html may be much "longer" proportionally, so we "fit" it to the expected page or thumbnail size
return htmlToImage(htmlComponent, new Dimensions(width, height));
}