Skip to content

Commit

Permalink
Fixed a bug related to cropping images from top=0 & left=0
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyank Parashar committed Mar 15, 2016
1 parent c48db68 commit c794bef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/getFilterInfosAndTargetContentTypeFromQueryString.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ function isNumberWithin(num, min, max) {
}

function isValidOperation(name, args) {
var maxDimension = 16384;
switch (name) {
case 'crop':
return args.length === 1 && /^(?:east|west|center|north(?:|west|east)|south(?:|west|east))/.test(args[0]);
case 'rotate':
return args.length === 0 || (args.length === 1 && (args[0] === 0 || args[0] === 90 || args[0] === 180 || args[0] === 270));
case 'resize':
return args.length === 2 && isNumberWithin(args[0], 1, 16384) && isNumberWithin(args[1], 1, 16384);
return args.length === 2 && isNumberWithin(args[0], 1, maxDimension) && isNumberWithin(args[1], 1, maxDimension);
case 'extract':
return args.length === 4 && isNumberWithin(args[0], 1, 16384) && isNumberWithin(args[1], 1, 16384) && isNumberWithin(args[2], 1, 16384) && isNumberWithin(args[3], 1, 16384);
return args.length === 4 && isNumberWithin(args[0], 0, maxDimension - 1) && isNumberWithin(args[1], 0, maxDimension - 1) && isNumberWithin(args[2], 1, maxDimension) && isNumberWithin(args[3], 1, maxDimension);
case 'interpolateWith':
return args.length === 1 && /^(?:nearest|bilinear|vertexSplitQuadraticBasisSpline|bicubic|locallyBoundedBicubic|nohalo)$/.test(args[0]);
case 'background':
Expand Down
6 changes: 6 additions & 0 deletions test/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ describe('express-processimage', function () {
);
});

it('should work fine when cropping an item starting from top 0 and left 0', function () {
return expect('GET /turtle.jpg?extract=0,0,300,200', 'to yield response', {
body: expect.it('to resemble', pathModule.resolve(__dirname, '..', 'testdata', 'turtleCropped300x200FromTopLeft.jpg'))
});
});

describe('with the gm engine', function () {
it('should allow a crop operation with a gravity of center', function () {
return expect('GET /turtle.jpg?gm&resize=40,15&crop=center', 'to yield response', {
Expand Down
Binary file added testdata/turtleCropped300x200FromTopLeft.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit c794bef

@papandreou
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks a bunch :)

Please sign in to comment.