Skip to content

Node.js based forum software built for the modern web

added image file

Baris Soner Usakli20ec8ca7688b
diff --git a/src/image.js b/src/image.js
new file mode 100644
index 0000000000..36e463bb88
--- /dev/null
+++ b/src/image.js
@@ -0,0 +1,46 @@
+
+var fs = require('fs'),
+ imagemagick = require('node-imagemagick'),
+ meta = require('./meta');
+
+var image = {};
+
+image.resizeImage = function(path, extension, width, height, callback) {
+ function done(err, stdout, stderr) {
+ callback(err);
+ }
+
+ if(extension === '.gif') {
+ imagemagick.convert([path, '-coalesce', '-repage', '0x0', '-crop', width+'x'+height+'+0+0', '+repage', 'uploadPath'], done);
+ } else {
+ imagemagick.crop({
+ srcPath: path,
+ dstPath: path,
+ width: width,
+ height: height
+ }, 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) {
+ return callback(err);
+ }
+
+ fs.writeFile(path, stdout, 'binary', callback);
+ });
+ } else {
+ callback();
+ }
+};
+
+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 file