fix: create sharp file for fileHasAdjustments files or fileIsAnimated files (#6708)
## Description Fixes #6694 Previously we were only creating sharp files for files that have file adjustments but instead a sharp file should be created for animated images even if there are no file adjustments - i.e `const fileHasAdjustments = fileSupportsResize && Boolean(resizeOptions || formatOptions || imageSizes || trimOptions || file.tempFilePath)` - [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
This commit is contained in:
@@ -133,21 +133,23 @@ export const generateFileData = async <T>({
|
|||||||
|
|
||||||
if (fileIsAnimated) sharpOptions.animated = true
|
if (fileIsAnimated) sharpOptions.animated = true
|
||||||
|
|
||||||
if (fileHasAdjustments && sharp) {
|
if (sharp && (fileIsAnimated || fileHasAdjustments)) {
|
||||||
if (file.tempFilePath) {
|
if (file.tempFilePath) {
|
||||||
sharpFile = sharp(file.tempFilePath, sharpOptions).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081
|
sharpFile = sharp(file.tempFilePath, sharpOptions).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081
|
||||||
} else {
|
} else {
|
||||||
sharpFile = sharp(file.data, sharpOptions).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081
|
sharpFile = sharp(file.data, sharpOptions).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resizeOptions) {
|
if (fileHasAdjustments) {
|
||||||
sharpFile = sharpFile.resize(resizeOptions)
|
if (resizeOptions) {
|
||||||
}
|
sharpFile = sharpFile.resize(resizeOptions)
|
||||||
if (formatOptions) {
|
}
|
||||||
sharpFile = sharpFile.toFormat(formatOptions.format, formatOptions.options)
|
if (formatOptions) {
|
||||||
}
|
sharpFile = sharpFile.toFormat(formatOptions.format, formatOptions.options)
|
||||||
if (trimOptions) {
|
}
|
||||||
sharpFile = sharpFile.trim(trimOptions)
|
if (trimOptions) {
|
||||||
|
sharpFile = sharpFile.trim(trimOptions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +203,6 @@ export const generateFileData = async <T>({
|
|||||||
let fileForResize = file
|
let fileForResize = file
|
||||||
|
|
||||||
if (cropData && sharp) {
|
if (cropData && sharp) {
|
||||||
const metadata = await sharpFile.metadata()
|
|
||||||
const { data: croppedImage, info } = await cropImage({ cropData, dimensions, file, sharp })
|
const { data: croppedImage, info } = await cropImage({ cropData, dimensions, file, sharp })
|
||||||
|
|
||||||
filesToSave.push({
|
filesToSave.push({
|
||||||
@@ -215,7 +216,11 @@ export const generateFileData = async <T>({
|
|||||||
size: info.size,
|
size: info.size,
|
||||||
}
|
}
|
||||||
fileData.width = info.width
|
fileData.width = info.width
|
||||||
fileData.height = fileIsAnimated ? info.height / metadata.pages : info.height
|
fileData.height = info.height
|
||||||
|
if (fileIsAnimated) {
|
||||||
|
const metadata = await sharpFile.metadata()
|
||||||
|
fileData.height = info.height / metadata.pages
|
||||||
|
}
|
||||||
fileData.filesize = info.size
|
fileData.filesize = info.size
|
||||||
|
|
||||||
if (file.tempFilePath) {
|
if (file.tempFilePath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user