Skip to content

Commit

Permalink
Merge bbc2a42 into fb0b6be
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Sep 3, 2019
2 parents fb0b6be + bbc2a42 commit 307ee60
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 75 deletions.
11 changes: 0 additions & 11 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
parser: 'babel-eslint',
extends: [
'onelint'
]
Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "8"
- "10"
- "12"
env:
- CXX=g++-4.8
addons:
Expand All @@ -15,3 +13,4 @@ addons:
- g++-4.8
before_install: "sudo apt-get update && sudo apt-get install -y libcairo2-dev libjpeg8-dev libgif-dev optipng pngcrush pngquant libpango1.0-dev graphicsmagick libjpeg-turbo-progs inkscape gifsicle"
script: "npm run-script travis"
after_success: '<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js'
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
require('babel-core/register');
require('babel-polyfill');
module.exports = require('./src/');
57 changes: 20 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,43 @@
"rotate"
],
"scripts": {
"coverage": "nyc --reporter=lcov -- npm test && echo Coverage Report written to coverage/lcov-repot/index.html",
"coverage": "nyc --reporter=lcov --reporter=text -- npm test && echo Coverage Report written to coverage/lcov-report/index.html",
"test": "mocha",
"lint": "eslint .",
"build": "babel src --out-dir lib --source-maps inline",
"clean": "rm -rf lib coverage .nyc_output",
"clean:build": "rm -rf lib",
"prepublish": "(in-publish && npm run build && npm run prepareIndex) 2> /dev/null || exit 0",
"postpublish": "(in-publish && npm run clean:build && npm run restoreIndex) 2> /dev/null || exit 0",
"prepareIndex": "mv index.js index.js.tmp && (echo \"module.exports = require('./lib/main');\" > index.js)",
"restoreIndex": "rm index.js && mv index.js.tmp index.js",
"travis": "npm test && npm run lint && npm run coverage && (<coverage/lcov.info coveralls || true)"
"travis": "npm run lint && npm run coverage"
},
"devDependencies": {
"animated-gif-detector": "1.1.7",
"babel-cli": "6.6.5",
"babel-core": "6.7.2",
"babel-eslint": "6.0.0-beta.6",
"babel-plugin-add-module-exports": "0.1.2",
"babel-plugin-transform-async-functions": "6.5.0",
"babel-plugin-transform-regenerator": "6.6.5",
"babel-plugin-transform-runtime": "6.6.0",
"babel-polyfill": "6.7.2",
"babel-preset-es2015": "6.6.0",
"coveralls": "2.11.9",
"eslint": "2.4.0",
"eslint-config-onelint": "1.0.2",
"gifsicle-stream": "0.2.0",
"gm": "1.23.0",
"in-publish": "2.0.0",
"coveralls": "^3.0.6",
"eslint": "^5.16.0",
"eslint-config-onelint": "4.0.0",
"gifsicle-stream": "1.0.0",
"gm": "1.23.1",
"inkscape": "1.1.0",
"jpegtran": "1.0.4",
"jsdom": "github:papandreou/jsdom#4a83791ba9d20b243723ae5cb50571b302e294ec",
"jpegtran": "1.0.6",
"jsdom": "^15.1.1",
"memoizesync": "0.5.0",
"mocha": "3.2.0",
"nyc": "10.1.2",
"optipng": "1.0.0",
"sharp": "0.17.1",
"mocha": "6.2.0",
"nyc": "^14.1.1",
"optipng": "2.1.0",
"sharp": "0.23.0",
"sinon": "1.17.7",
"svgfilter": "1.2.0",
"unexpected": "10.22.2",
"unexpected-dom": "3.1.1",
"unexpected-image": "2.0.0",
"unexpected-resemble": "3.1.0",
"svgfilter": "3.0.0",
"unexpected": "10.40.2",
"unexpected-dom": "4.13.1",
"unexpected-image": "3.1.0",
"unexpected-resemble": "4.2.0",
"unexpected-sinon": "10.6.0",
"unexpected-stream": "2.0.4"
},
"dependencies": {
"babel-runtime": "^5.0.0",
"combine-stream": "0.0.4",
"createerror": "1.1.0",
"exif-reader": "1.0.0",
"icc": "0.0.2",
"lodash": "4.6.1",
"mime": "1.3.4",
"lodash": "^4.17.15",
"mime": "^1.6.0",
"require-or": "0.0.2"
}
}
11 changes: 5 additions & 6 deletions src/Impro.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*global JSON*/
let _ = require('lodash');
let mime = require('mime');
let Pipeline = require('./Pipeline');
var _ = require('lodash');
var mime = require('mime');
var Pipeline = require('./Pipeline');

mime.define({
'image/vnd.microsoft.icon': ['ico']
});

export default class Impro {
module.exports = class Impro {
constructor(options, operations) {
if (typeof options === 'string' || Array.isArray(options)) {
operations = options;
Expand Down Expand Up @@ -145,4 +144,4 @@ export default class Impro {
leftover: leftOverQueryStringFragments.join('&')
};
}
}
};
4 changes: 2 additions & 2 deletions src/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var Stream = require('stream');
var _ = require('lodash');
let mime = require('mime');

export default class Pipeline extends Stream.Duplex {
module.exports = class Pipeline extends Stream.Duplex {
constructor(impro, options) {
super();
this._queuedOperations = [];
Expand Down Expand Up @@ -186,4 +186,4 @@ export default class Pipeline extends Stream.Duplex {
this.options.maxInputPixels = maxInputPixels;
return this;
}
}
};
28 changes: 26 additions & 2 deletions src/engines/sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ function isNumberWithin(num, min, max) {
return typeof num === 'number' && num >= min && num <= max;
}

function locatePreviousCommand(operations, nameToFind) {
return operations.find(operation => {
return operation.name === nameToFind;
});
}

var maxDimension = 16384;

module.exports = {
Expand Down Expand Up @@ -64,17 +70,35 @@ module.exports = {
if (options.sequentialRead) {
sharpInstance = sharpInstance.sequentialRead();
}

var operationsForExecution = [];
operations.forEach(function (operation) {
var name = operation.name;
var args = operation.args;
if (operation.name === 'resize' && typeof pipeline.options.maxOutputPixels === 'number' && args[0] * args[1] > pipeline.options.maxOutputPixels) {
throw new errors.OutputDimensionsExceeded('resize: Target dimensions of ' + args[0] + 'x' + args[1] + ' exceed maxOutputPixels (' + pipeline.options.maxOutputPixels + ')');
}
// in sharp crop is implemented as options to resize
if (operation.name === 'crop') {
name = 'resize';
args = [ null, null, { fit: 'cover', position: args[0] } ];

const locatedOperation = locatePreviousCommand(operationsForExecution, name);
if (locatedOperation) {
locatedOperation.args[2] = args[2];
return;
}
}
// Compensate for https://github.com/lovell/sharp/issues/276
if (operation.name === 'extract' && args.length >= 4) {
if (name === 'extract' && args.length >= 4) {
args = [ { left: args[0], top: args[1], width: args[2], height: args[3] } ];
}
return sharpInstance[operation.name](...args);

operationsForExecution.push({ name, args });
});

operationsForExecution.map(({ name, args }) => sharpInstance[name](...args));

pipeline.add(sharpInstance);
}
};
14 changes: 7 additions & 7 deletions test/impro.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ describe('impro', function () {
format: 'JPEG'
}
))
.then(() => expect(cacheSpy, 'to have calls satisfying', () => cacheSpy(123)))
.finally(() => cacheSpy.restore());
.then(() => expect(cacheSpy, 'to have calls satisfying', () => cacheSpy(123)))
.finally(() => cacheSpy.restore());
}));
});

Expand All @@ -286,11 +286,11 @@ describe('impro', function () {
'cat.gif',
'when piped through',
impro.gifsicle().resize(380, 486).extract(150, 150, 100, 100)),
'to yield output satisfying',
expect.it('to have metadata satisfying', {
size: { width: 100, height: 100 },
Scene: '3 of 4' // Animated
}).and('to resemble', load('cat-resized-then-cropped.gif')
'to yield output satisfying',
expect.it('to have metadata satisfying', {
size: { width: 100, height: 100 },
Scene: '3 of 4' // Animated
}).and('to resemble', load('cat-resized-then-cropped.gif')
);
});

Expand Down
2 changes: 0 additions & 2 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
--require babel-core/register
--require babel-polyfill
1 change: 1 addition & 0 deletions testdata/addBogusElement.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*globals svgFilter:false*/
var bogus = document.createElement('bogus');
bogus.setAttribute('id', svgFilter.bogusElementId || 'blablaf');
document.documentElement.appendChild(bogus);
Binary file modified testdata/turtleCroppedCenter.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 307ee60

Please sign in to comment.