Skip to content

Commit

Permalink
Made sharp an optional dependency (waiting for lovell/sharp#42).
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Oct 23, 2014
1 parent 4c28203 commit 675619a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions lib/getFilterInfosAndTargetContentTypeFromQueryString.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Stream = require('stream'),
gm = require('gm'),
sharp = require('sharp'),
isOperationByEngineNameAndName = {gm: {}, sharp: {}},
sharp,
isOperationByEngineNameAndName = {gm: {}},
filterConstructorByOperationName = {};

['PngQuant', 'PngCrush', 'OptiPng', 'JpegTran', 'Inkscape', 'SvgFilter'].forEach(function (constructorName) {
Expand All @@ -20,9 +20,16 @@ Object.keys(gm.prototype).forEach(function (propertyName) {
}
});

['resize', 'extract', 'sequentialRead', 'crop', 'max', 'background', 'embed', 'flatten', 'rotate', 'flip', 'flop', 'withoutEnlargement', 'sharpen', 'interpolateWith', 'gamma', 'grayscale', 'greyscale', 'jpeg', 'webp', 'quality', 'progressive', 'withMetadata', 'compressionLevel'].forEach(function (sharpOperationName) {
isOperationByEngineNameAndName.sharp[sharpOperationName] = true;
});
try {
sharp = require('sharp');
} catch (e) {}

if (sharp) {
isOperationByEngineNameAndName.sharp = {};
['resize', 'extract', 'sequentialRead', 'crop', 'max', 'background', 'embed', 'flatten', 'rotate', 'flip', 'flop', 'withoutEnlargement', 'sharpen', 'interpolateWith', 'gamma', 'grayscale', 'greyscale', 'jpeg', 'webp', 'quality', 'progressive', 'withMetadata', 'compressionLevel'].forEach(function (sharpOperationName) {
isOperationByEngineNameAndName.sharp[sharpOperationName] = true;
});
}

var engineNamesByOperationName = {};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"optipng": "0.1.1",
"passerror": "0.0.1",
"pngcrush": "0.1.0",
"pngquant": "0.3.0",
"sharp": "0.7.0"
"pngquant": "0.3.0"
},
"optionalDependencies": {
"sharp": "0.7.0",
"svgfilter": "0.4.0"
},
"devDependencies": {
Expand Down

1 comment on commit 675619a

@lovell
Copy link

@lovell lovell commented on 675619a Oct 24, 2014

Choose a reason for hiding this comment

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

Hej @papandreou, are you able to help test the libvips+dependencies installation script I've added as part of lovell/sharp#42?

Please sign in to comment.