UNPKG

@yireen/squoosh-browser

Version:

An image compression tool run in browser while @squoosh/lib can not.

13 lines (12 loc) 411 B
export function getContainOffsets(sw, sh, dw, dh) { const currentAspect = sw / sh; const endAspect = dw / dh; if (endAspect > currentAspect) { const newSh = sw / endAspect; const newSy = (sh - newSh) / 2; return { sw, sh: newSh, sx: 0, sy: newSy }; } const newSw = sh * endAspect; const newSx = (sw - newSw) / 2; return { sh, sw: newSw, sx: newSx, sy: 0 }; }