import sharp from 'sharp' export default function ImageHelpers() { return { image: sharp(), // https://sharp.pixelplumbing.com/api-constructor#sharp async open(src: string) { return (this.image = src ? sharp(src) : this.image) }, // https://sharp.pixelplumbing.com/api-output#tobuffer async toBuffer(sharpImg?: sharp.Sharp) { sharpImg = sharpImg || this.image return await sharpImg.png().toBuffer() }, // https://sharp.pixelplumbing.com/api-resize cover(width: number, height?: number) { return (this.image = this.image.resize({ width, height: height || width, })) }, // https://sharp.pixelplumbing.com/api-composite composite(compositeAry: sharp.OverlayOptions[]) { return (this.image = this.image.composite(compositeAry)) }, } }