xxxxxxxxxx
// replace sharp with jimp instead bcos there are common issues relating to alpine linux based c-library it depends on
// https://sharp.pixelplumbing.com/install#common-problems
// https://www.appsloveworld.com/nodejs/100/63/express-sharp-install-via-docker-issue
// https://completecoding.io/automatic-resizing-of-uploaded-images/
// https://medium.com/@mehdi_kernel/the-sharp-package-and-docker-on-apple-silicon-3f38900745fe
const resizeImage = async ({ bucket, file, width, height }) => {
const imageBuffer = await S3.get(file, bucket);
import S3 from '../common/S3';
import jimp from 'jimp';
// With this jimp package installed we can use it to resize the image.
const jimpImage = await jimp.read(imageBuffer.Body);
const mime = jimpImage.getMIME();
const resizedImageBuffer = await jimpImage.scaleToFit(width, height).getBufferAsync(mime);
return resizedImageBuffer
}