| Current Path : /var/www/homesaver/www/bitrix/js/ui/text-editor/src/helpers/ |
| Current File : /var/www/homesaver/www/bitrix/js/ui/text-editor/src/helpers/calc-image-size.js |
export function calcImageSize(previewWidth, previewHeight, renderWidth, renderHeight): [number, number]
{
const ratioWidth: number = renderWidth / previewWidth;
const ratioHeight: number = renderHeight / previewHeight;
const ratio: number = Math.min(ratioWidth, ratioHeight);
const useOriginalSize = ratio > 1; // image is too small
const width = useOriginalSize ? previewWidth : previewWidth * ratio;
const height = useOriginalSize ? previewHeight : previewHeight * ratio;
return [width, height];
}