From 42282dc43d6ccd7e390bff67a34a42d760f36027 Mon Sep 17 00:00:00 2001 From: Nicolas Chambrier Date: Fri, 18 Oct 2013 09:58:09 +0200 Subject: [PATCH 1/2] Add option "extension" to "imageVersions" to convert upload Automatically convert to given extension using following syntax: ```javascript imageVersions: { thumbnail: { width: 80, height: 80, extension: "png" } } ``` --- lib/uploadhandler.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index ece4b55..09f1a5d 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -103,11 +103,15 @@ module.exports = function (options) { counter++; var opts = options.imageVersions[version]; + var dstName = fileInfo.name; + if (opts.extension) { + dstName = path.basename(dstName, path.extname(dstName)) + '.' + opts.extension; + } imageMagick.resize({ width: opts.width, height: opts.height, srcPath: options.uploadDir() + '/' + fileInfo.name, - dstPath: options.uploadDir() + '/' + version + '/' + fileInfo.name, + dstPath: options.uploadDir() + '/' + version + '/' + dstName, customArgs: opts.imageArgs || ['-auto-orient'] }, finish); }); From 98fcda77c5e0dd05e86e4dc2653ca2435bd55c0c Mon Sep 17 00:00:00 2001 From: Nicolas Chambrier Date: Fri, 18 Oct 2013 20:13:34 +0200 Subject: [PATCH 2/2] Fix compatibility with res.json() --- lib/filehandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filehandler.js b/lib/filehandler.js index bab6f89..0fad294 100644 --- a/lib/filehandler.js +++ b/lib/filehandler.js @@ -16,7 +16,7 @@ module.exports = function (middleware, options) { ? 'application/json' : 'text/plain' }); - res.json(200, result); + res.json(result); } });