mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix getImageProcessingLibrary usage
This commit is contained in:
@@ -96,7 +96,7 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lib = await getImageProcessingLibrary()
|
const lib = await getImageProcessingLibrary()
|
||||||
if('sharp' in lib && lib.sharp?.default) {
|
if('sharp' in lib && typeof lib.sharp?.default === 'function') {
|
||||||
const img = lib.sharp!.default(bufferOrFilePath)
|
const img = lib.sharp!.default(bufferOrFilePath)
|
||||||
const dimensions = await img.metadata()
|
const dimensions = await img.metadata()
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
|
|||||||
height: dimensions.height,
|
height: dimensions.height,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else if('jimp' in lib && lib.jimp) {
|
} else if('jimp' in lib && typeof lib.jimp.read === 'function') {
|
||||||
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp
|
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp
|
||||||
|
|
||||||
const jimp = await read(bufferOrFilePath as any)
|
const jimp = await read(bufferOrFilePath as any)
|
||||||
@@ -153,14 +153,14 @@ export const generateProfilePicture = async(mediaUpload: WAMediaUpload) => {
|
|||||||
|
|
||||||
const lib = await getImageProcessingLibrary()
|
const lib = await getImageProcessingLibrary()
|
||||||
let img: Promise<Buffer>
|
let img: Promise<Buffer>
|
||||||
if('sharp' in lib) {
|
if('sharp' in lib && typeof lib.sharp?.default === 'function') {
|
||||||
img = lib.sharp!.default(bufferOrFilePath)
|
img = lib.sharp!.default(bufferOrFilePath)
|
||||||
.resize(640, 640)
|
.resize(640, 640)
|
||||||
.jpeg({
|
.jpeg({
|
||||||
quality: 50,
|
quality: 50,
|
||||||
})
|
})
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
} else {
|
} else if('jimp' in lib && typeof lib.jimp.read === 'function') {
|
||||||
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp
|
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp
|
||||||
const jimp = await read(bufferOrFilePath as any)
|
const jimp = await read(bufferOrFilePath as any)
|
||||||
const min = Math.min(jimp.getWidth(), jimp.getHeight())
|
const min = Math.min(jimp.getWidth(), jimp.getHeight())
|
||||||
@@ -170,6 +170,8 @@ export const generateProfilePicture = async(mediaUpload: WAMediaUpload) => {
|
|||||||
.quality(50)
|
.quality(50)
|
||||||
.resize(640, 640, RESIZE_BILINEAR)
|
.resize(640, 640, RESIZE_BILINEAR)
|
||||||
.getBufferAsync(MIME_JPEG)
|
.getBufferAsync(MIME_JPEG)
|
||||||
|
} else {
|
||||||
|
throw new Boom('No image processing library available')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user