site-library/packages/imagetoolsNew/plugin/utils/imagetools.js
2025-03-08 21:04:49 +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 }
}