diff --git a/packages/payload/src/uploads/imageResizer.ts b/packages/payload/src/uploads/imageResizer.ts index 24b07df5fe..233085825d 100644 --- a/packages/payload/src/uploads/imageResizer.ts +++ b/packages/payload/src/uploads/imageResizer.ts @@ -131,7 +131,7 @@ const preventResize = ( const isWidthOrHeightNotDefined = !desiredHeight || !desiredWidth if (isWidthOrHeightNotDefined) { - // If with and height are not defined, it means there is a format conversion + // If width and height are not defined, it means there is a format conversion // and the image needs to be "resized" (transformed). return false // needs resize } @@ -156,9 +156,10 @@ const preventResize = ( * @returns true if the image should passed directly to sharp */ const applyPayloadAdjustments = ( - { height, width, withoutEnlargement, withoutReduction }: ImageSize, + { fit, height, width, withoutEnlargement, withoutReduction }: ImageSize, original: ProbedImageSize, ) => { + if (fit === 'contain' || fit === 'inside') return false if (!isNumber(height) && !isNumber(width)) return false const targetAspectRatio = width / height diff --git a/test/uploads/config.ts b/test/uploads/config.ts index 1421e47788..40410baab2 100644 --- a/test/uploads/config.ts +++ b/test/uploads/config.ts @@ -96,6 +96,41 @@ export default buildConfigWithDefaults({ }, fields: [], }, + { + slug: 'object-fit', + upload: { + staticURL: '/object-fit', + staticDir: './object-fit', + mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'], + imageSizes: [ + { + name: 'fitContain', + width: 400, + height: 300, + fit: 'contain', + }, + { + name: 'fitInside', + width: 300, + height: 400, + fit: 'inside', + }, + { + name: 'fitCover', + width: 900, + height: 300, + fit: 'cover', + }, + { + name: 'fitOutside', + width: 900, + height: 200, + fit: 'outside', + }, + ], + }, + fields: [], + }, { slug: 'crop-only', upload: {