fix(payload): resizes images first before applying focal point (#7277)
Fixes #7275
This commit is contained in:
@@ -312,23 +312,21 @@ export async function resizeAndTransformImageSizes({
|
||||
if (!resizeHeight) resizeHeight = resizeImageMeta.height
|
||||
if (!resizeWidth) resizeWidth = resizeImageMeta.width
|
||||
|
||||
// if requested image is larger than the incoming size, then resize using sharp and then extract with focal point
|
||||
if (resizeHeight > resizeImageMeta.height || resizeWidth > resizeImageMeta.width) {
|
||||
const resizeAspectRatio = resizeWidth / resizeHeight
|
||||
const prioritizeHeight = resizeAspectRatio < originalAspectRatio
|
||||
resized = imageToResize.resize({
|
||||
height: prioritizeHeight ? resizeHeight : undefined,
|
||||
width: prioritizeHeight ? undefined : resizeWidth,
|
||||
})
|
||||
const resizeAspectRatio = resizeWidth / resizeHeight
|
||||
const prioritizeHeight = resizeAspectRatio < originalAspectRatio
|
||||
// Scales the image before extracting from it
|
||||
resized = imageToResize.resize({
|
||||
height: prioritizeHeight ? resizeHeight : undefined,
|
||||
width: prioritizeHeight ? undefined : resizeWidth,
|
||||
})
|
||||
|
||||
// must read from buffer, resize.metadata will return the original image metadata
|
||||
const { info } = await resized.toBuffer({ resolveWithObject: true })
|
||||
resizeImageMeta.height = extractHeightFromImage({
|
||||
...originalImageMeta,
|
||||
height: info.height,
|
||||
})
|
||||
resizeImageMeta.width = info.width
|
||||
}
|
||||
// must read from buffer, resize.metadata will return the original image metadata
|
||||
const { info } = await resized.toBuffer({ resolveWithObject: true })
|
||||
resizeImageMeta.height = extractHeightFromImage({
|
||||
...originalImageMeta,
|
||||
height: info.height,
|
||||
})
|
||||
resizeImageMeta.width = info.width
|
||||
|
||||
const halfResizeX = resizeWidth / 2
|
||||
const xFocalCenter = resizeImageMeta.width * (incomingFocalPoint.x / 100)
|
||||
|
||||
Reference in New Issue
Block a user