image-handler.js
486 Bytes
const MAX_WIDTH = 1000;
export function getArticleImageSize({width, height, minScale = 0.75, maxWidth = MAX_WIDTH}) {
width = +width;
height = +height;
if (width > maxWidth) {
height = height / (width / maxWidth);
width = maxWidth;
}
if (minScale && width / height < minScale) {
height = width / minScale;
}
if (width === 1) {
width = maxWidth / 2;
}
if (height === 1) {
height = maxWidth / 2;
}
return {width, height: Math.round(height)};
}