mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Keep aspect ratio when generating thumbnails (#1409)
* fix: generated thumbnail ratio * Delete myvid.mp4 * Delete thumb.jpeg
This commit is contained in:
@@ -81,7 +81,7 @@ const extractVideoThumb = async(
|
|||||||
time: string,
|
time: string,
|
||||||
size: { width: number; height: number },
|
size: { width: number; height: number },
|
||||||
) => new Promise((resolve, reject) => {
|
) => new Promise((resolve, reject) => {
|
||||||
const cmd = `ffmpeg -ss ${time} -i ${path} -y -s ${size.width}x${size.height} -vframes 1 -f image2 ${destPath}`
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`
|
||||||
exec(cmd, (err) => {
|
exec(cmd, (err) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
@@ -99,17 +99,17 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
|
|||||||
const lib = await getImageProcessingLibrary()
|
const lib = await getImageProcessingLibrary()
|
||||||
if('sharp' in lib) {
|
if('sharp' in lib) {
|
||||||
const result = await lib.sharp!.default(bufferOrFilePath)
|
const result = await lib.sharp!.default(bufferOrFilePath)
|
||||||
.resize(32, 32)
|
.resize(32)
|
||||||
.jpeg({ quality: 50 })
|
.jpeg({ quality: 50 })
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
const { read, MIME_JPEG, RESIZE_BILINEAR } = 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)
|
||||||
const result = await jimp
|
const result = await jimp
|
||||||
.quality(50)
|
.quality(50)
|
||||||
.resize(32, 32, RESIZE_BILINEAR)
|
.resize(32, AUTO, RESIZE_BILINEAR)
|
||||||
.getBufferAsync(MIME_JPEG)
|
.getBufferAsync(MIME_JPEG)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user