diff --git a/src/Utils/link-preview.ts b/src/Utils/link-preview.ts index 12f976a..0146f0f 100644 --- a/src/Utils/link-preview.ts +++ b/src/Utils/link-preview.ts @@ -41,7 +41,7 @@ export const getUrlInfo = async( let jpegThumbnail: Buffer | undefined = undefined try { jpegThumbnail = image - ? await getCompressedJpegThumbnail(image, opts) + ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined } catch(error) { logger?.debug( diff --git a/src/Utils/messages-media.ts b/src/Utils/messages-media.ts index 12a6296..8e209e0 100644 --- a/src/Utils/messages-media.ts +++ b/src/Utils/messages-media.ts @@ -97,20 +97,35 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str const lib = await getImageProcessingLibrary() if('sharp' in lib) { - const result = await lib.sharp!.default(bufferOrFilePath) + const img = lib.sharp!.default(bufferOrFilePath) + const dimensions = await img.metadata() + + const buffer = await img .resize(width) .jpeg({ quality: 50 }) .toBuffer() - return result + return { + buffer, + original: { + width: dimensions.width, + height: dimensions.height, + }, + } } else { const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp const jimp = await read(bufferOrFilePath as any) - const result = await jimp + const buffer = await jimp .quality(50) .resize(width, AUTO, RESIZE_BILINEAR) .getBufferAsync(MIME_JPEG) - return result + return { + buffer, + original: { + width: jimp.getWidth(), + height: jimp.getHeight() + } + } } } @@ -224,8 +239,8 @@ export async function generateThumbnail( ) { let thumbnail: string | undefined if(mediaType === 'image') { - const buff = await extractImageThumb(file) - thumbnail = buff.toString('base64') + const { buffer } = await extractImageThumb(file) + thumbnail = buffer.toString('base64') } else if(mediaType === 'video') { const imgFilename = join(getTmpFilesDirectory(), generateMessageID() + '.jpg') try {