forked from external-repos/squoosh
* Port resize to wasm * Expose resize algorithms * Lanczos3 working! * lol copy paste * Adding support for other resizers * Don’t track generated README * Cache wasm instance
15 lines
419 B
TypeScript
15 lines
419 B
TypeScript
export function getContainOffsets(sw: number, sh: number, dw: number, dh: number) {
|
|
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 };
|
|
}
|