mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 02:29:50 +00:00
# Conflicts: # codecs/cpp.Dockerfile # codecs/imagequant/example.html # codecs/webp/dec/webp_dec.d.ts # codecs/webp/dec/webp_dec.js # codecs/webp/dec/webp_dec.wasm # codecs/webp/enc/webp_enc.d.ts # codecs/webp/enc/webp_enc.js # codecs/webp/enc/webp_enc.wasm # package-lock.json # package.json # src/codecs/tiny.webp # src_old/codecs/encoders.ts # src_old/codecs/processor-worker/tiny.avif # src_old/codecs/processor-worker/tiny.webp # src_old/codecs/tiny.webp # src_old/components/compress/index.tsx # src_old/lib/util.ts # src_old/sw/util.ts
20 lines
430 B
TypeScript
20 lines
430 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 };
|
|
}
|