From eb8e285bc41a3a3b4743c8821a4408949d661660 Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Tue, 14 Jul 2020 22:34:52 +0530 Subject: [PATCH] switched from sharp to jimp for img processing --- package.json | 3 +-- src/WAClient/Utils.ts | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6e943bb..3135095 100644 --- a/package.json +++ b/package.json @@ -32,16 +32,15 @@ "dependencies": { "curve25519-js": "0.0.4", "futoin-hkdf": "^1.3.2", + "jimp": "^0.14.0", "node-fetch": "^2.6.0", "protobufjs": "^6.9.0", "qrcode-terminal": "^0.12.0", - "sharp": "^0.25.4", "ws": "^7.3.0" }, "devDependencies": { "@types/mocha": "^7.0.2", "@types/node": "^14.0.14", - "@types/sharp": "^0.25.0", "@types/ws": "^7.2.6", "@typescript-eslint/eslint-plugin": "^3.5.0", "@typescript-eslint/parser": "^3.5.0", diff --git a/src/WAClient/Utils.ts b/src/WAClient/Utils.ts index a5e4ad6..fe057fd 100644 --- a/src/WAClient/Utils.ts +++ b/src/WAClient/Utils.ts @@ -1,5 +1,5 @@ import { MessageType, HKDFInfoKeys, MessageOptions, WAMessageType } from './Constants' -import sharp from 'sharp' +import Jimp from 'jimp' import * as fs from 'fs' import fetch from 'node-fetch' import { WAMessage, WAMessageContent } from '../WAConnection/Constants' @@ -60,8 +60,10 @@ const extractVideoThumb = async ( }) }) as Promise -export const compressImage = async (buffer: Buffer) => sharp(buffer).resize(48, 48).jpeg().toBuffer() - +export const compressImage = async (buffer: Buffer) => { + const jimp = await Jimp.read (buffer) + return jimp.resize(48, 48).getBufferAsync (Jimp.MIME_JPEG) +} /** generates a thumbnail for a given media, if required */ export async function generateThumbnail(buffer: Buffer, mediaType: MessageType, info: MessageOptions) { if (info.thumbnail === null || info.thumbnail) {