fixed #1161 properly - Merge remote-tracking branch 'origin/master'

Conflicts:
	src/upgrade.js
v1.18.x
Julian Lam 11 years ago
commit 4a1513eabf

@ -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",

@ -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;

@ -3,7 +3,6 @@ var fs = require('fs'),
winston = require('winston'),
nconf = require('nconf'),
async= require('async'),
imagemagick = require('node-imagemagick'),
user = require('./../user'),
posts = require('./../posts'),
@ -117,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!'
});
@ -124,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!'
});
@ -131,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!'
});
@ -185,6 +187,7 @@ var fs = require('fs'),
}
if(err) {
fs.unlink(req.files.userPhoto.path);
return res.send({error:err.message});
}

Loading…
Cancel
Save