Permalink
Browse files

Replace blur from gm with blur from sharp

  • Loading branch information...
1 parent 3594124 commit 334e18c772e028a5fb5717e0001ecf742f016412 @DMarby committed Nov 11, 2014
Showing with 9 additions and 18 deletions.
  1. +8 −16 imageProcessor.js
  2. +1 −2 package.json
View
@@ -1,5 +1,3 @@
-var gm = require('gm')
-
module.exports = exports = function (sharp, path, config, fs) {
var ImageProcessor = {
'getProcessedImage': function (width, height, gravity, gray, blur, filePath, shortName, callback) {
@@ -9,23 +7,13 @@ module.exports = exports = function (sharp, path, config, fs) {
return callback(null, destination)
}
- ImageProcessor.imageResize(width, height, gravity, filePath, destination, gray, function (error, destination) {
+ ImageProcessor.imageResize(width, height, gravity, filePath, destination, gray, blur, function (error, destination) {
if (error) {
ImageProcessor.deleteFile(destination)
return callback(error)
}
-
- if (blur) {
- gm(destination).blur(0, 5).write(destination, function (error) {
- if (error) {
- ImageProcessor.deleteFile(destination)
- return callback(error)
- }
- callback(null, destination)
- })
- } else {
- callback(null, destination)
- }
+
+ callback(null, destination)
})
})
},
@@ -51,14 +39,18 @@ module.exports = exports = function (sharp, path, config, fs) {
return config.cache_folder_path + '/' + prefix + width + '^' + height + '-' + gravity + (blur ? '-blurred' : '') + '.jpeg'
},
- 'imageResize': function (width, height, gravity, filePath, destination, gray, callback) {
+ 'imageResize': function (width, height, gravity, filePath, destination, gray, blur, callback) {
try {
var image = sharp(filePath).rotate().resize(width, height).crop(sharp.gravity[gravity]);
if (gray) {
image.grayscale()
}
+ if (blur) {
+ image.blur(10)
+ }
+
image.jpeg().progressive().toFile(destination, function (error) {
callback(error, destination)
})
View
@@ -14,8 +14,7 @@
"dependencies": {
"cors": "^2.4.2",
"express": "^4.8.2",
- "gm": "^1.16.0",
- "sharp": "git://github.com/lovell/sharp.git",
+ "sharp": "git://github.com/lovell/sharp.git#edge",
"socket.io": "^1.0.6",
"vnstat-dumpdb": "^1.0.2",
"async": "^0.9.0"

0 comments on commit 334e18c

Please sign in to comment.