fix: proper height data for animated gifs (#2506)

This commit is contained in:
Elliot DeNolf
2023-04-17 11:34:31 -04:00
committed by GitHub
parent 0f8051b577
commit aee6ca05cc
2 changed files with 37 additions and 3 deletions

View File

@@ -108,10 +108,13 @@ export const generateFileData = async <T>({
}
if (sharpFile) {
const metadata = await sharpFile.metadata();
fileBuffer = await sharpFile.toBuffer({ resolveWithObject: true });
({ mime, ext } = await fromBuffer(fileBuffer.data));
({ mime, ext } = await fromBuffer(fileBuffer.data)); // This is getting an incorrect gif height back.
fileData.width = fileBuffer.info.width;
fileData.height = fileBuffer.info.height;
// Animated GIFs aggregate the height from every frame, so we need to use divide by number of pages
fileData.height = sharpOptions.animated ? (fileBuffer.info.height / metadata.pages) : fileBuffer.info.height;
fileData.filesize = fileBuffer.data.length;
} else {
mime = file.mimetype;