diff --git a/packages/image/src/crop-rectangle.js b/packages/image/src/crop-rectangle.js index 68f211059..803876ea0 100644 --- a/packages/image/src/crop-rectangle.js +++ b/packages/image/src/crop-rectangle.js @@ -43,6 +43,18 @@ module.exports = ({ width, height, cropDimensions }) => { cropped: false, }); } + + const coords = ['x1', 'x2', 'y1', 'y2']; + if (coords.some(key => cropDimensions[key] == null || Number.isNaN(cropDimensions[key]))) { + return new CropRectangle({ + x: 0, + y: 0, + width, + height, + cropped: false, + }); + } + // @see Cygnus\ApplicationBundle\Apps\Management\Controller::cropImageAction const scale = width / 640; const { @@ -50,25 +62,11 @@ module.exports = ({ width, height, cropDimensions }) => { x2, y1, y2, - } = ['x1', 'x2', 'y1', 'y2'].reduce((o, key) => { + } = coords.reduce((o, key) => { const v = Math.round(cropDimensions[key] * scale); return { ...o, [key]: v }; }, {}); - if ( - typeof x1 !== 'number' - || typeof x2 !== 'number' - || typeof y1 !== 'number' - || typeof y2 !== 'number' - ) { - return new CropRectangle({ - x: 0, - y: 0, - width, - height, - cropped: false, - }); - } return new CropRectangle({ x: x1,