image-handler.js 453 Bytes
const MAX_WIDTH = 1000;

export function getArticleImageSize({width, height, MIN_SCALE = 0.75}) {
  width = +width;
  height = +height;
  if (width > MAX_WIDTH) {
    height = height / (width / MAX_WIDTH);
    width = MAX_WIDTH;
  }

  if (MIN_SCALE && width / height < MIN_SCALE) {
    height = width / MIN_SCALE;
  }
  if (width === 1) {
    width = MAX_WIDTH / 2;
  }
  if (height === 1) {
    height = MAX_WIDTH / 2;
  }
  return {width, height};
}