From 6275b85eaebb0d1ff6c4054bc5dd90774fac9d38 Mon Sep 17 00:00:00 2001 From: Catalin Bozan <43291246+catabozan@users.noreply.github.com> Date: Fri, 25 Mar 2022 12:53:38 +0200 Subject: [PATCH] Keep aspect ratio when generating thumbnails (#1409) * fix: generated thumbnail ratio * Delete myvid.mp4 * Delete thumb.jpeg --- src/Utils/messages-media.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utils/messages-media.ts b/src/Utils/messages-media.ts index d9c8e27..e8599bc 100644 --- a/src/Utils/messages-media.ts +++ b/src/Utils/messages-media.ts @@ -81,7 +81,7 @@ const extractVideoThumb = async( time: string, size: { width: number; height: number }, ) => new Promise((resolve, reject) => { - const cmd = `ffmpeg -ss ${time} -i ${path} -y -s ${size.width}x${size.height} -vframes 1 -f image2 ${destPath}` + const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}` exec(cmd, (err) => { if(err) { reject(err) @@ -99,17 +99,17 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str const lib = await getImageProcessingLibrary() if('sharp' in lib) { const result = await lib.sharp!.default(bufferOrFilePath) - .resize(32, 32) + .resize(32) .jpeg({ quality: 50 }) .toBuffer() return result } else { - const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp + const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp const jimp = await read(bufferOrFilePath as any) const result = await jimp .quality(50) - .resize(32, 32, RESIZE_BILINEAR) + .resize(32, AUTO, RESIZE_BILINEAR) .getBufferAsync(MIME_JPEG) return result }