UNPKG

@jrmc/adonis-attachment

Version:

Turn any field on your Lucid model to an attachment data type

27 lines (26 loc) 789 B
/** * @jrmc/adonis-attachment * * @license MIT * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr> */ import Converter from './converter.js'; import { use } from '../utils/helpers.js'; export default class ImageConverter extends Converter { async handle({ input, options }) { const sharp = await use('sharp'); const resize = options?.resize || {}; let format = options?.format || 'webp'; let formatoptions = {}; if (typeof format !== 'string') { formatoptions = format?.options; format = format.format; } const buffer = await sharp(input) .withMetadata() .resize(resize) .toFormat(format, formatoptions) .toBuffer(); return buffer; } }