immp
Advanced tools
Comparing version 1.4.1 to 1.4.2
{ | ||
"name": "immp", | ||
"description": "Image Manipulation Middleware Proxy", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"repository": "garrows/IMMP", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -18,2 +18,3 @@ var _ = require('underscore'), | ||
imageDir: process.cwd(), | ||
// convertTo: {}, | ||
@@ -133,32 +134,39 @@ }, _config); | ||
var gmImage = gm(_imageSrc, image.hash).options(gmOptions); | ||
async.waterfall([ | ||
//Get original content-type | ||
// Get image format/content-type | ||
function (_callback) { | ||
gmImage.format({ | ||
bufferStream: true | ||
}, function (_error, _format) { | ||
if(_error) { | ||
console.log(_error); | ||
return _callback(_error); | ||
} | ||
image.format = _format; | ||
if(!_res.headersSent) { | ||
_res.header('Content-Type', 'image/' + _format.toLowerCase()); | ||
} | ||
}, _callback); | ||
}, | ||
function (_format, _callback) { | ||
// Check if we should convert. | ||
var newFormat; | ||
var mimeType; | ||
_format = _format.toLowerCase(); | ||
_callback(null); | ||
}); | ||
if(config.convertTo && config.convertTo[_format] && config.convertTo[_format].fileType && config.convertTo[_format].fileType.toLowerCase() !== _format) { | ||
newFormat = config.convertTo[_format].fileType.toLowerCase(); | ||
gmImage.setFormat(newFormat); | ||
mimeType = config.convertTo[_format].mimeType; | ||
_format = newFormat; | ||
} | ||
image.format = _format; | ||
if(!mimeType) { | ||
mimeType = _format.toLowerCase(); | ||
} | ||
if(!_res.headersSent) { | ||
_res.header('Content-Type', 'image/' + mimeType); | ||
} | ||
_callback(null); | ||
}, | ||
// Custom crop as per request | ||
function (_callback) { | ||
// All params should exist and be numeric. | ||
var hasCrop = _.every(customCrop, function(param){ | ||
var hasCrop = _.every(customCrop, function (param) { | ||
var num = Number(param); | ||
return !isNaN(num) && num >= 0; | ||
}); | ||
if(hasCrop){ | ||
gmImage.crop( customCrop.w, customCrop.h, customCrop.x, customCrop.y ); | ||
if(hasCrop) { | ||
gmImage.crop(customCrop.w, customCrop.h, customCrop.x, customCrop.y); | ||
} | ||
@@ -168,3 +176,3 @@ _callback(null); | ||
//Get original size (after initial crop) | ||
// Get size (after initial crop) | ||
function (_callback) { | ||
@@ -283,2 +291,2 @@ gmImage.size({ | ||
}; | ||
}; | ||
}; |
@@ -15,16 +15,29 @@ var async = require('async'), | ||
graphicsMagick: true | ||
}; | ||
}, | ||
serverImmpConfig = { | ||
// ttl: 0, | ||
// ttl: 1000 * 60 * 60 * 24 * 7, // 1 week | ||
imageMagick: false, | ||
graphicsMagick: true, | ||
cacheFolder: process.cwd() + '/.tmp/immp', | ||
// allowProxy: true, | ||
imageDir: process.cwd() + '/public' | ||
}, | ||
server, | ||
serverPort = process.env.PORT || 3000, | ||
serverUrl = 'http://localhost:' + serverPort; | ||
var server = 'http://localhost:' + (process.env.PORT || 3000); | ||
describe('immp', function () { | ||
before(function (_done) { | ||
cluster.setupMaster({ | ||
exec: path.join(cwd, '/bin/www') | ||
// Set up the test server. | ||
var debug = require('debug')('gm'); | ||
var app = require('../app')(serverImmpConfig); | ||
app.set('port', serverPort); | ||
server = app.listen(app.get('port'), function () { | ||
debug('Express server listening on port ' + serverPort); | ||
_done(); | ||
}); | ||
cluster.fork(); | ||
setTimeout(function () { | ||
_done(); | ||
}, 300); | ||
}); | ||
@@ -43,4 +56,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&resize=200x0', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&resize=200x0', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -66,4 +80,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&resize=0x200', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&resize=0x200', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -89,4 +104,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&resize=2000x2000', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&resize=2000x2000', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -113,4 +129,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&resize=2000x2000&upscale=true', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&resize=2000x2000&upscale=true', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -137,4 +154,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&resize=100x200', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&resize=100x200', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -163,4 +181,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&crop=1x1', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&crop=1x1', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -187,4 +206,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&sx=0&sy=0&sw=100&sh=111', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&sx=0&sy=0&sw=100&sh=111', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -211,4 +231,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&sx=100&sy=100&sw=222&sh=111', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&sx=100&sy=100&sw=222&sh=111', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -231,10 +252,10 @@ | ||
describe('with invalid operators', function(){ | ||
describe('with invalid operators', function () { | ||
[ | ||
[0,0,0,0], // No image | ||
[99999,99999,100,100], // Outside bounds | ||
['a',0,0,0], // Non-numeric | ||
[-1,0,0,0], // Not positive | ||
['',0,0,0], // Not defined | ||
].forEach(function(params){ | ||
[0, 0, 0, 0], // No image | ||
[99999, 99999, 100, 100], // Outside bounds | ||
['a', 0, 0, 0], // Non-numeric | ||
[-1, 0, 0, 0], // Not positive | ||
['', 0, 0, 0], // Not defined | ||
].forEach(function (params) { | ||
it('should not do a custom crop with ' + params, function (_done) { | ||
@@ -244,4 +265,5 @@ this.slow(5000); | ||
http.get(server + '/im/?image=/images/robot.jpg&sx='+params[0]+'&sy='+params[1]+'&sw='+params[2]+'&sh='+params[3]+'', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&sx=' + params[0] + '&sy=' + params[1] + '&sw=' + params[2] + '&sh=' + params[3] + '', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -271,4 +293,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&crop=9x16', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&crop=9x16', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -296,4 +319,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&crop=16x9', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&crop=16x9', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -320,4 +344,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -349,4 +374,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&quality=invalidQualityValue', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&quality=invalidQualityValue', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -368,4 +394,5 @@ | ||
http.get(server + '/im/?image=/images/robot.jpg&quality=50', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/robot.jpg&quality=50', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -397,4 +424,5 @@ | ||
http.get(server + '/im/?image=/images/Landscape_8.jpg&quality=50', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/Landscape_8.jpg&quality=50', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -420,4 +448,5 @@ | ||
http.get(server + '/im/?image=' + server + '/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=' + serverUrl + '/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -444,4 +473,5 @@ | ||
http.get(server + '/im/?image=https://www.google.com/images/srpr/logo11w.png&crop=1x1&resize=50x100', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=https://www.google.com/images/srpr/logo11w.png&crop=1x1&resize=50x100', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/png'); | ||
@@ -465,4 +495,5 @@ | ||
it('should still have the right content-type & size when cached', function (_done) { | ||
http.get(server + '/im/?image=/images/Landscape_8.jpg&quality=50', function (_httpResponse) { | ||
http.get(serverUrl + '/im/?image=/images/Landscape_8.jpg&quality=50', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/jpeg'); | ||
@@ -484,2 +515,54 @@ | ||
}); | ||
it('should return gifs', function (_done) { | ||
http.get(serverUrl + '/im/?image=/images/captainplanet.gif', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/gif'); | ||
_done(); | ||
}); | ||
}); | ||
describe('with convertTo set', function () { | ||
before(function (_done) { | ||
// Clear file cache. | ||
var immpFiles = fs.readdirSync(immpPath); | ||
immpFiles.forEach(function (_file) { | ||
fs.unlinkSync(path.join(immpPath, '/', _file)); | ||
}); | ||
// Recreate server with new config option/s. | ||
server.on('close', function () { | ||
serverImmpConfig.convertTo = { | ||
gif: { | ||
fileType: 'png32', | ||
mimeType: 'png' | ||
} | ||
}; | ||
// Set up the test server. | ||
var debug = require('debug')('gm'); | ||
var app = require('../app')(serverImmpConfig); | ||
app.set('port', serverPort); | ||
server = app.listen(app.get('port'), function () { | ||
debug('Express server listening on port ' + serverPort); | ||
_done(); | ||
}); | ||
}); | ||
server.close(); | ||
}); | ||
it('should return in the appropriate format', function (_done) { | ||
http.get(serverUrl + '/im/?image=/images/captainplanet.gif', function (_httpResponse) { | ||
_httpResponse.statusCode.should.eql(200); | ||
_httpResponse.headers['content-type'].should.eql('image/png'); | ||
gm(_httpResponse) | ||
.options(gmOptions).format(function (error, format) { | ||
format.should.eql('PNG'); | ||
_done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
641
26185
9
4