immp
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "immp", | ||
"description": "Image Manipulation Middleware Proxy", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"repository": "garrows/IMMP", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -21,4 +21,5 @@ var _ = require('underscore'), | ||
return function(_req, _res, _next) { | ||
var dimensions = _req.query.resize || '0x0'; | ||
var crop = _req.query.crop || '0x0'; | ||
var dimensions = _req.query.resize || '0x0', | ||
crop = _req.query.crop || '0x0', | ||
quality = _req.query.quality; | ||
@@ -48,2 +49,3 @@ var gmOptions = {}; | ||
}, | ||
quality: cast(quality, 'number'), | ||
upscale: /true/i.test(_req.query.upscale) | ||
@@ -154,3 +156,2 @@ }; | ||
// console.log('Cropped', image.size, "to", newSize, "offset", offset); | ||
gmImage.crop( | ||
@@ -175,2 +176,10 @@ newSize.width, | ||
// Quality | ||
function(_callback) { | ||
if (typeof image.quality === 'number') { | ||
gmImage.quality(image.quality); | ||
} | ||
_callback(); | ||
} | ||
], function(_error) { | ||
@@ -209,2 +218,2 @@ | ||
} | ||
} | ||
} |
@@ -225,2 +225,49 @@ var async = require('async'), | ||
it('should set the quality', function(_done) { | ||
this.slow(5000); | ||
this.timeout(10000); | ||
async.waterfall([ | ||
// Get the size without compression | ||
function(_callback) { | ||
http.get('http://localhost:3000/im/?image=/images/robot.jpg&quality=invalidQualityValue', function(_httpResponse) { | ||
gm(_httpResponse) | ||
.options(gmOptions) | ||
.filesize(function(_error, _filesize) { | ||
if (_error) return _callback(_error); | ||
_callback(null, parseInt(_filesize)); | ||
}); | ||
}); | ||
}, | ||
// Get the size with compression | ||
function(_fileSizeWithoutCompression, _callback) { | ||
http.get('http://localhost:3000/im/?image=/images/robot.jpg&quality=50', function(_httpResponse) { | ||
gm(_httpResponse) | ||
.options(gmOptions) | ||
.filesize(function(_error, _filesize) { | ||
if (_error) return _callback(_error); | ||
var filesize = parseInt(_filesize); | ||
filesize.should.be.lessThan(_fileSizeWithoutCompression); | ||
(filesize / _fileSizeWithoutCompression).should.be.greaterThan(.5).and.lessThan(.8); | ||
_callback(null, filesize); | ||
}); | ||
}); | ||
} | ||
], function(_error) { | ||
_done(_error); | ||
}); | ||
}); | ||
}); |
1132514
38
366