mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
🖼️ feat: Avatar GIF Support & Dynamic Extensions (#7657)
This commit is contained in:
parent
aca89091d9
commit
442b149d55
7 changed files with 58 additions and 10 deletions
|
|
@ -44,8 +44,25 @@ async function resizeAvatar({ userId, input, desiredFormat = EImageOutputType.PN
|
|||
throw new Error('Invalid input type. Expected URL, Buffer, or File.');
|
||||
}
|
||||
|
||||
const { width, height } = await sharp(imageBuffer).metadata();
|
||||
const metadata = await sharp(imageBuffer).metadata();
|
||||
const { width, height } = metadata;
|
||||
const minSize = Math.min(width, height);
|
||||
|
||||
if (metadata.format === 'gif') {
|
||||
const resizedBuffer = await sharp(imageBuffer, { animated: true })
|
||||
.extract({
|
||||
left: Math.floor((width - minSize) / 2),
|
||||
top: Math.floor((height - minSize) / 2),
|
||||
width: minSize,
|
||||
height: minSize,
|
||||
})
|
||||
.resize(250, 250)
|
||||
.gif()
|
||||
.toBuffer();
|
||||
|
||||
return resizedBuffer;
|
||||
}
|
||||
|
||||
const squaredBuffer = await sharp(imageBuffer)
|
||||
.extract({
|
||||
left: Math.floor((width - minSize) / 2),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue