mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 10:09:45 +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
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
import {
|
|
builtinResize,
|
|
BuiltinResizeMethod,
|
|
drawableToImageData,
|
|
} from '../../lib/util';
|
|
import { BrowserResizeOptions, VectorResizeOptions } from './processor-meta';
|
|
import { getContainOffsets } from './util';
|
|
|
|
export function browserResize(
|
|
data: ImageData,
|
|
opts: BrowserResizeOptions,
|
|
): ImageData {
|
|
let sx = 0;
|
|
let sy = 0;
|
|
let sw = data.width;
|
|
let sh = data.height;
|
|
|
|
if (opts.fitMethod === 'contain') {
|
|
({ sx, sy, sw, sh } = getContainOffsets(sw, sh, opts.width, opts.height));
|
|
}
|
|
|
|
return builtinResize(
|
|
data,
|
|
sx,
|
|
sy,
|
|
sw,
|
|
sh,
|
|
opts.width,
|
|
opts.height,
|
|
opts.method.slice('browser-'.length) as BuiltinResizeMethod,
|
|
);
|
|
}
|
|
|
|
export function vectorResize(
|
|
data: HTMLImageElement,
|
|
opts: VectorResizeOptions,
|
|
): ImageData {
|
|
let sx = 0;
|
|
let sy = 0;
|
|
let sw = data.width;
|
|
let sh = data.height;
|
|
|
|
if (opts.fitMethod === 'contain') {
|
|
({ sx, sy, sw, sh } = getContainOffsets(sw, sh, opts.width, opts.height));
|
|
}
|
|
|
|
return drawableToImageData(data, {
|
|
sx,
|
|
sy,
|
|
sw,
|
|
sh,
|
|
width: opts.width,
|
|
height: opts.height,
|
|
});
|
|
}
|