switched from sharp to jimp for img processing

This commit is contained in:
Adhiraj
2020-07-14 22:34:52 +05:30
parent 970f333bb4
commit eb8e285bc4
2 changed files with 6 additions and 5 deletions

View File

@@ -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",

View File

@@ -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<void>
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) {