This repository has been archived on 2025-12-24. You can view files and clone it, but cannot push or open issues or pull requests.
site-template/packages/imagetools/plugin/utils/imagetools.js
2025-03-07 14:59:06 +01:00

27 lines
549 B
JavaScript

// @ts-check
import {
builtins,
loadImage,
applyTransforms,
generateTransforms,
} from "imagetools-core";
export const getLoadedImage = async (src) => {
const image = loadImage(src);
const { width } = await image.metadata();
return { image, width };
};
export const getTransformedImage = async ({ image, config }) => {
const { transforms } = generateTransforms(config, builtins);
const { image: encodedImage } = await applyTransforms(
transforms,
image.clone()
);
return { image: encodedImage, buffer: null };
};