@thi.ng/imago
Version:
JSON & API-based declarative and extensible image processing trees/pipelines
30 lines (29 loc) • 790 B
JavaScript
import { defmulti } from "@thi.ng/defmulti";
import { colorLayerImpl } from "../layers/color.js";
import { imageLayerImpl } from "../layers/image.js";
import { rawLayerImpl } from "../layers/raw.js";
import { svgLayerImpl } from "../layers/svg.js";
import { textLayerImpl } from "../layers/text.js";
const compositeProc = async (spec, input, ctx) => {
const { layers } = spec;
const layerSpecs = await Promise.all(
layers.map((l) => defLayer(l, input, ctx))
);
ctx.logger.debug("layer specs", layerSpecs);
return [input.composite(layerSpecs), true];
};
const defLayer = defmulti(
(x) => x.type,
{},
{
color: colorLayerImpl,
img: imageLayerImpl,
raw: rawLayerImpl,
svg: svgLayerImpl,
text: textLayerImpl
}
);
export {
compositeProc,
defLayer
};