UNPKG

349 BJavaScriptView Raw
1
2export function calculatePreferedImageSize( image, container ) {
3 const maxWidth = container.clientWidth;
4 const exceedMaxWidth = image.width > maxWidth;
5 const ratio = image.height / image.width;
6 const width = exceedMaxWidth ? maxWidth : image.width;
7 const height = exceedMaxWidth ? maxWidth * ratio : image.height;
8 return { width, height };
9}