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

Commit

Permalink
Replace falsy check of coordinates with proper numeric check
Browse files Browse the repository at this point in the history
  • Loading branch information
benurb committed Sep 9, 2015
1 parent 2f0793a commit 7413087
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/cropImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ module.exports = function(res, done) {
shot = gm(this.screenshot).quality(100),
cropDim;

if (this.currentArgs.x && this.currentArgs.y && this.currentArgs.width && this.currentArgs.height) {
var x = parseInt(this.currentArgs.x, 10);
var y = parseInt(this.currentArgs.y, 10);
var width = parseInt(this.currentArgs.width, 10);
var height = parseInt(this.currentArgs.height, 10);

if (!isNaN(x) && !isNaN(y) && !isNaN(width) && !isNaN(height)) {

/**
* crop image with given arguments
*/
cropDim = {
x: this.currentArgs.x - res.scrollPos.x,
y: this.currentArgs.y - res.scrollPos.y,
width: this.currentArgs.width,
height: this.currentArgs.height
x: x - res.scrollPos.x,
y: y - res.scrollPos.y,
width: width,
height: height
};

exclude(shot, excludeRect);
Expand All @@ -39,8 +44,8 @@ module.exports = function(res, done) {
cropDim = {
x: res.elemBounding.left + (res.elemBounding.width / 2),
y: res.elemBounding.top + (res.elemBounding.height / 2),
width: typeof this.currentArgs.width !== 'undefined' ? this.currentArgs.width : res.elemBounding.width,
height: typeof this.currentArgs.height !== 'undefined' ? this.currentArgs.height : res.elemBounding.height
width: isNaN(width) ? res.elemBounding.width : width,
height: isNaN(height) ? res.elemBounding.height : height
};

exclude(shot, excludeRect);
Expand Down

0 comments on commit 7413087

Please sign in to comment.