Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #482 from Shinsina/check-dim
Browse files Browse the repository at this point in the history
Ensure dimensions are actually numbers, crop dimensions within crop rectangle.
zarathustra323 authored Nov 7, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 803329a + add140d commit 75c2a77
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/image/src/crop-rectangle.js
Original file line number Diff line number Diff line change
@@ -43,32 +43,30 @@ 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 {
x1,
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,

0 comments on commit 75c2a77

Please sign in to comment.