fix: #14033, fix gif profile images

add test
This commit is contained in:
Barış Soner Uşaklı
2026-03-01 19:48:53 -05:00
parent dcc4670749
commit 06bf2abfc4
4 changed files with 33 additions and 8 deletions

View File

@@ -40,13 +40,14 @@ image.resizeImage = async function (data) {
width: data.width,
height: data.height,
quality: data.quality,
type: data.type,
});
} else {
const sharp = requireSharp();
const buffer = await fs.promises.readFile(data.path);
const sharpImage = sharp(buffer, {
failOnError: true,
animated: data.path.endsWith('gif'),
animated: data.type === 'image/gif',
});
const metadata = await sharpImage.metadata();

View File

@@ -87,10 +87,12 @@ module.exports = function (User) {
throw new Error('[[error:invalid-image-extension]]');
}
const newPath = await convertToPNG(userPhoto.path);
const normalizedPath = await convertToPNG(userPhoto.path);
const isNormalized = userPhoto.path !== normalizedPath;
await image.resizeImage({
path: newPath,
path: normalizedPath,
type: isNormalized ? 'image/png' : userPhoto.type,
width: meta.config.profileImageDimension,
height: meta.config.profileImageDimension,
});
@@ -98,7 +100,7 @@ module.exports = function (User) {
const filename = generateProfileImageFilename(data.uid, extension);
const uploadedImage = await image.uploadImage(filename, `profile/uid-${data.uid}`, {
uid: data.uid,
path: newPath,
path: normalizedPath,
name: 'profileAvatar',
});
@@ -124,17 +126,19 @@ module.exports = function (User) {
}
validateUpload(data, meta.config.maximumProfileImageSize, User.getAllowedImageTypes());
const extension = file.typeToExtension(image.mimeFromBase64(data.imageData));
const type = image.mimeFromBase64(data.imageData);
const extension = file.typeToExtension(type);
if (!extension) {
throw new Error('[[error:invalid-image-extension]]');
}
picture.path = await image.writeImageDataToTempFile(data.imageData);
picture.path = await convertToPNG(picture.path);
const normalizedPath = await convertToPNG(picture.path);
const isNormalized = picture.path !== normalizedPath;
picture.path = normalizedPath;
await image.resizeImage({
path: picture.path,
type: isNormalized ? 'image/png' : type,
width: meta.config.profileImageDimension,
height: meta.config.profileImageDimension,
});