@thi.ng/imago
Version:
JSON & API-based declarative and extensible image processing trees/pipelines
31 lines (30 loc) • 995 B
JavaScript
import { isNumber } from "@thi.ng/checks";
import { resizeProc } from "./resize.js";
const maxsizeProc = async (spec, input, ctx) => {
const { maxSize } = spec;
const [width, height] = ctx.size;
const result = [input, false];
if (isNumber(maxSize)) {
if (width > maxSize || height > maxSize)
return resizeProc(
{ ...spec, size: maxSize, unit: "px" },
input,
ctx
);
} else {
const [maxW, maxH] = maxSize;
const resizeWidth = maxW > 0 && width > maxW;
const resizeHeight = maxH > 0 && height > maxH;
const specW = { ...spec, size: [maxW, -1], unit: "px" };
const specH = { ...specW, size: [-1, maxH] };
if (width >= height) {
return resizeWidth ? resizeProc(specW, input, ctx) : resizeHeight ? resizeProc(specH, input, ctx) : result;
} else {
return resizeHeight ? resizeProc(specH, input, ctx) : resizeWidth ? resizeProc(specW, input, ctx) : result;
}
}
return result;
};
export {
maxsizeProc
};