Node.js based forum software built for the modern web
closes #1130
Baris Soner Usakli096f352c82d1
diff --git a/package.json b/package.jsonindex 083db7f7a0..79d2d26c33 100644--- a/package.json+++ b/package.json@@ -23,7 +23,7 @@"less-middleware": "0.1.12","marked": "0.2.8","async": "~0.2.8",- "node-imagemagick": "0.1.8",+ "gm": "1.14.2","gravatar": "1.0.6","nconf": "~0.6.7","sitemap": "~0.7.1",diff --git a/src/image.js b/src/image.jsindex 97bb237a16..5f92773fa8 100644--- a/src/image.js+++ b/src/image.js@@ -1,6 +1,7 @@+'use strict';var fs = require('fs'),- imagemagick = require('node-imagemagick'),+ gm = require('gm').subClass({imageMagick: true}),meta = require('./meta');var image = {};@@ -11,35 +12,26 @@ image.resizeImage = function(path, extension, width, height, callback) {}if(extension === '.gif') {- imagemagick.convert([- path,- '-coalesce',- '-repage',- '0x0',- '-crop',- width+'x'+height+'+0+0',- '+repage',- path- ], done);+ gm().in(path)+ .in('-coalesce')+ .in('-resize')+ .in(width+'x'+height)+ .write(path, done);} else {- imagemagick.crop({- srcPath: path,- dstPath: path,- width: width,- height: height- }, done);+ gm(path)+ .crop(width, height, 0, 0)+ .write(path, done);}};image.convertImageToPng = function(path, extension, callback) {var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);if(convertToPNG && extension !== '.png') {- imagemagick.convert([path, 'png:-'], function(err, stdout) {- if(err) {+ gm(path).toBuffer('png', function(err, buffer) {+ if (err) {return callback(err);}-- fs.writeFile(path, stdout, 'binary', callback);+ fs.writeFile(path, buffer, 'binary', callback);});} else {callback();@@ -50,6 +42,6 @@ image.convertImageToBase64 = function(path, callback) {fs.readFile(path, function(err, data) {callback(err, data ? data.toString('base64') : null);});-}+};module.exports = image;\ No newline at end of filediff --git a/src/routes/user.js b/src/routes/user.jsindex 641404f8a6..db25182b2a 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -116,6 +116,7 @@ var fs = require('fs'),var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;if (req.files.userPhoto.size > uploadSize * 1024) {+ fs.unlink(req.files.userPhoto.path);return res.send({error: 'Images must be smaller than ' + uploadSize + ' kb!'});@@ -123,6 +124,7 @@ var fs = require('fs'),var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {+ fs.unlink(req.files.userPhoto.path);return res.send({error: 'Allowed image types are png, jpg and gif!'});@@ -130,6 +132,7 @@ var fs = require('fs'),var extension = path.extname(req.files.userPhoto.name);if (!extension) {+ fs.unlink(req.files.userPhoto.path);return res.send({error: 'Error uploading file! Error : Invalid extension!'});@@ -184,6 +187,7 @@ var fs = require('fs'),}if(err) {+ fs.unlink(req.files.userPhoto.path);return res.send({error:err.message});}