@thi.ng/imago
Version:
JSON & API-based declarative and extensible image processing trees/pipelines
29 lines (28 loc) • 645 B
JavaScript
import { readText } from "@thi.ng/file-io";
import { positionOrGravity } from "../utils.js";
import { illegalArgs } from "@thi.ng/errors";
const svgLayerImpl = async (layer, _, ctx) => {
let {
type: __,
body,
gravity,
origin,
path,
pos,
ref,
unit,
...opts
} = layer;
if (path) body = readText(path, ctx.logger);
if (!body) illegalArgs("missing SVG doc");
const w = +(/width="(\d+)"/.exec(body)?.[1] || 0);
const h = +(/height="(\d+)"/.exec(body)?.[1] || 0);
return {
input: Buffer.from(body),
...positionOrGravity([w, h], ctx.size, layer),
...opts
};
};
export {
svgLayerImpl
};