Skip to content

Commit

Permalink
Changes to support resize + crop=center for gm
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyank Parashar committed Mar 4, 2016
1 parent 19bda18 commit 03a5886
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
32 changes: 32 additions & 0 deletions lib/getFilterInfosAndTargetContentTypeFromQueryString.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ module.exports = function getFilterInfosAndTargetContentTypeFromQueryString(quer
if (options.maxInputPixels) {
gmInstance.limit('pixels', options.maxInputPixels);
}
var resize;
var crop;
for (var i = 0 ; i < gmOperationsForThisInstance.length ; i += 1) {
var gmOperation = gmOperationsForThisInstance[i];
if (gmOperation.name === 'resize') {
resize = gmOperation;
} else if (gmOperation.name === 'crop') {
crop = gmOperation;
}
}
if (resize && crop) {
gmOperationsForThisInstance.push({
name: 'extent',
args: [].concat(resize.args)
});
resize.args.push('^');
}
gmOperationsForThisInstance.reduce(function (gmInstance, gmOperation) {
checkSharpOrGmOperation(gmOperation);
if (gmOperation.name === 'rotate' && gmOperation.args.length === 1) {
Expand All @@ -145,6 +162,21 @@ module.exports = function getFilterInfosAndTargetContentTypeFromQueryString(quer
if (gmOperation.name === 'extract') {
gmOperation.name = 'crop';
gmOperation.args = [gmOperation.args[2], gmOperation.args[3], gmOperation.args[0], gmOperation.args[1]];
} else if (gmOperation.name === 'crop') {
gmOperation.name = 'gravity';
gmOperation.args = [
{
northwest: 'NorthWest',
north: 'North',
northeast: 'NorthEast',
west: 'West',
center: 'Center',
east: 'East',
southwest: 'SouthWest',
south: 'South',
southeast: 'SouthEast'
}[String(gmOperation.args[0]).toLowerCase()] || 'Center'
];
}
if (!gmInstance[gmOperation.name]) {
gmOperation = _.extend({}, gmOperation);
Expand Down
14 changes: 11 additions & 3 deletions test/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,17 @@ describe('express-processimage', function () {
);
});

it.skip('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', {
body: expect.it('to resemble', pathModule.resolve(__dirname, '..', 'testdata', 'turtleCroppedCenter.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', {
body: expect.it('to resemble', pathModule.resolve(__dirname, '..', 'testdata', 'turtleCroppedCenterGm.jpg'))
});
});

it('should allow a crop operation with a gravity of northeast', function () {
return expect('GET /turtle.jpg?gm&resize=40,15&crop=northeast', 'to yield response', {
body: expect.it('to resemble', pathModule.resolve(__dirname, '..', 'testdata', 'turtleCroppedNorthEastGm.jpg'))
});
});
});
});
Binary file added testdata/turtleCroppedCenterGm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testdata/turtleCroppedNorthEastGm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 03a5886

Please sign in to comment.