Skip to content

Commit 10c6ffa

Browse files
authored
fix: only use metadata.pages for height if animated (#6728)
## Description ### Issue: Non-animated webp / gif files were using `metadata.pages` to calculate it's resized heights for `imageSizes` or `cropping`. ### Fix: It should only use this to calculate it's height if the file's `metadata` contains `metadata.pages`. Non-animated webps and gifs would not have this. - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] Existing test suite passes locally with my changes
1 parent 6512d5c commit 10c6ffa

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/payload/src/uploads/generateFileData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const generateFileData = async <T>({
219219
fileData.height = info.height
220220
if (fileIsAnimated) {
221221
const metadata = await sharpFile.metadata()
222-
fileData.height = info.height / metadata.pages
222+
fileData.height = metadata.pages ? info.height / metadata.pages : info.height
223223
}
224224
fileData.filesize = info.size
225225

packages/payload/src/uploads/imageResizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export async function resizeAndTransformImageSizes({
364364
name: imageResizeConfig.name,
365365
filename: imageNameWithDimensions,
366366
filesize: size,
367-
height: fileIsAnimated ? height / metadata.pages : height,
367+
height: fileIsAnimated && metadata.pages ? height / metadata.pages : height,
368368
mimeType: mimeInfo?.mime || mimeType,
369369
sizesToSave: [{ buffer: bufferData, path: imagePath }],
370370
width,

0 commit comments

Comments
 (0)