mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Bump Jimp && Sharp (#1575)
* Bump Jimp && Sharp Upgrade and use the latest version of jimp and sharp libraries * lint
This commit is contained in:
@@ -61,14 +61,14 @@
|
||||
"eslint-config-prettier": "^10.1.2",
|
||||
"eslint-plugin-prettier": "^5.4.0",
|
||||
"jest": "^29.7.0",
|
||||
"jimp": "^0.16.1",
|
||||
"jimp": "^1.6.0",
|
||||
"json": "^11.0.0",
|
||||
"link-preview-js": "^3.0.0",
|
||||
"open": "^8.4.2",
|
||||
"prettier": "^3.5.3",
|
||||
"protobufjs-cli": "^1.1.3",
|
||||
"release-it": "^15.10.3",
|
||||
"sharp": "^0.32.6",
|
||||
"sharp": "^0.34.2",
|
||||
"ts-jest": "^29.3.2",
|
||||
"ts-node": "^10.8.1",
|
||||
"typedoc": "^0.27.9",
|
||||
@@ -77,9 +77,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"audio-decode": "^2.1.3",
|
||||
"jimp": "^0.16.1",
|
||||
"jimp": "^1.6.0",
|
||||
"link-preview-js": "^3.0.0",
|
||||
"sharp": "^0.32.6"
|
||||
"sharp": "^0.34.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"audio-decode": {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { exec } from 'child_process'
|
||||
import * as Crypto from 'crypto'
|
||||
import { once } from 'events'
|
||||
import { createReadStream, createWriteStream, promises as fs, WriteStream } from 'fs'
|
||||
import { ResizeStrategy } from 'jimp'
|
||||
import type { IAudioMetadata } from 'music-metadata'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
@@ -32,22 +33,12 @@ import { ILogger } from './logger'
|
||||
const getTmpFilesDirectory = () => tmpdir()
|
||||
|
||||
const getImageProcessingLibrary = async () => {
|
||||
const [_jimp, sharp] = await Promise.all([
|
||||
(async () => {
|
||||
const jimp = await import('jimp').catch(() => {})
|
||||
return jimp
|
||||
})(),
|
||||
(async () => {
|
||||
const sharp = await import('sharp').catch(() => {})
|
||||
return sharp
|
||||
})()
|
||||
])
|
||||
const [jimp, sharp] = await Promise.all([import('jimp').catch(() => {}), import('sharp').catch(() => {})])
|
||||
|
||||
if (sharp) {
|
||||
return { sharp }
|
||||
}
|
||||
|
||||
const jimp = _jimp?.default || _jimp
|
||||
if (jimp) {
|
||||
return { jimp }
|
||||
}
|
||||
@@ -159,15 +150,15 @@ export const extractImageThumb = async (bufferOrFilePath: Readable | Buffer | st
|
||||
height: dimensions.height
|
||||
}
|
||||
}
|
||||
} else if ('jimp' in lib && typeof lib.jimp?.read === 'function') {
|
||||
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp
|
||||
|
||||
const jimp = await read(bufferOrFilePath as string)
|
||||
} else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'object') {
|
||||
const jimp = await lib.jimp.default.Jimp.read(bufferOrFilePath)
|
||||
const dimensions = {
|
||||
width: jimp.getWidth(),
|
||||
height: jimp.getHeight()
|
||||
width: jimp.width,
|
||||
height: jimp.height
|
||||
}
|
||||
const buffer = await jimp.quality(50).resize(width, AUTO, RESIZE_BILINEAR).getBufferAsync(MIME_JPEG)
|
||||
const buffer = await jimp
|
||||
.resize({ w: width, mode: ResizeStrategy.BILINEAR })
|
||||
.getBuffer('image/jpeg', { quality: 50 })
|
||||
return {
|
||||
buffer,
|
||||
original: dimensions
|
||||
@@ -207,13 +198,12 @@ export const generateProfilePicture = async (
|
||||
quality: 50
|
||||
})
|
||||
.toBuffer()
|
||||
} else if ('jimp' in lib && typeof lib.jimp?.read === 'function') {
|
||||
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp
|
||||
const jimp = await read(buffer)
|
||||
const min = Math.min(jimp.getWidth(), jimp.getHeight())
|
||||
const cropped = jimp.crop(0, 0, min, min)
|
||||
} else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'object') {
|
||||
const jimp = await lib.jimp.default.Jimp.read(buffer)
|
||||
const min = Math.min(jimp.width, jimp.height)
|
||||
const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min })
|
||||
|
||||
img = cropped.quality(50).resize(w, h, RESIZE_BILINEAR).getBufferAsync(MIME_JPEG)
|
||||
img = cropped.resize({ w, h, mode: ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 50 })
|
||||
} else {
|
||||
throw new Boom('No image processing library available')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user