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/imagetoolsNew/plugin/utils/imagetools.js
2025-03-07 14:59:06 +01:00

24 lines
576 B
JavaScript

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