Socket
Socket
Sign inDemoInstall

immp

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immp - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

.jsbeautifyrc

2

package.json
{
"name": "immp",
"description": "Image Manipulation Middleware Proxy",
"version": "1.1.3",
"version": "1.1.4",
"repository": "garrows/IMMP",

@@ -6,0 +6,0 @@ "keywords": [

@@ -8,5 +8,6 @@ var _ = require('underscore'),

gm = require('gm'),
https = require('https'),
http = require('http');
module.exports = function(_config) {
module.exports = function (_config) {
var config = _.extend({

@@ -16,3 +17,3 @@

ttl: 1000 * 60 * 60 * 24 * 7, // 1 week
allowProxy: false,
allowProxy: true,
imageDir: process.cwd(),

@@ -22,3 +23,3 @@

return function(_req, _res, _next) {
return function (_req, _res, _next) {
var dimensions = _req.query.resize || '0x0',

@@ -29,6 +30,6 @@ crop = _req.query.crop || '0x0',

var gmOptions = {};
if (config.imageMagick) {
if(config.imageMagick) {
gmOptions.imageMagick = config.imageMagick;
}
if (config.graphicsMagick) {
if(config.graphicsMagick) {
gmOptions.graphicsMagick = config.graphicsMagick;

@@ -56,3 +57,3 @@ }

if (config.allowProxy && !/^https?\:/.test(image.location)) {
if(config.allowProxy && !/^https?\:/.test(image.location)) {
image.location = image.location.trim().replace(/^\//, '');

@@ -69,3 +70,3 @@ image.location = _req.protocol + '://' + _req.headers.host + '/' + image.location;

*/
function(_callback) {
function (_callback) {
var stat,

@@ -78,5 +79,5 @@ createdAt = 0,

createdAt = cast(stat.mtime, 'date').getTime();
} catch (e) {};
} catch(e) {};
if (stat && now - createdAt < config.ttl) {
if(stat && now - createdAt < config.ttl) {
gm(config.cacheFolder + '/' + image.hash)

@@ -95,8 +96,12 @@ .options(gmOptions)

*/
function(_callback) {
if (config.allowProxy) {
http.get(image.location, function(_httpResponse) {
if (_httpResponse.statusCode >= 400) return _callback(new Error('status ' + _httpResponse.statusCode));
function (_callback) {
if(config.allowProxy) {
var client = http;
if(image.location.indexOf('https://') === 0) {
client = https;
}
client.get(image.location, function (_httpResponse) {
if(_httpResponse.statusCode >= 400) return _callback(new Error('status ' + _httpResponse.statusCode));
_callback(null, _httpResponse);
}).on('error', function(_error) {
}).on('error', function (_error) {
_callback(_error);

@@ -113,3 +118,3 @@ });

*/
function(_imageSrc, _manipulationDoneCallback) {
function (_imageSrc, _manipulationDoneCallback) {
var gmImage = gm(_imageSrc, image.hash).options(gmOptions);

@@ -120,7 +125,7 @@

//Get original size
function(_callback) {
function (_callback) {
gmImage.size({
bufferStream: true
}, function(_error, _size) {
if (_error) {
}, function (_error, _size) {
if(_error) {
console.log(_error);

@@ -136,5 +141,5 @@ return _callback(_error);

// Crop
function(_callback) {
function (_callback) {
// If a crop ratio has been specified
if (!(!image.crop.width && !image.crop.height)) {
if(!(!image.crop.width && !image.crop.height)) {

@@ -153,5 +158,5 @@ var newSize = {

if (sourceRatio < targetRatio) {
if(sourceRatio < targetRatio) {
newSize.height = image.size.width / targetRatio;
} else if (sourceRatio > targetRatio) {
} else if(sourceRatio > targetRatio) {
newSize.width = image.size.height * targetRatio;

@@ -177,5 +182,5 @@ } else {

// Resize
function(_callback) {
function (_callback) {
// If a width or height has been sepcified
if (!(!image.resize.width && !image.resize.height)) {
if(!(!image.resize.width && !image.resize.height)) {
gmImage.resize(image.resize.width, image.resize.height, image.upscale === true ? '' : '>');

@@ -187,4 +192,4 @@ }

// Quality
function(_callback) {
if (typeof image.quality === 'number') {
function (_callback) {
if(typeof image.quality === 'number') {
gmImage.quality(image.quality);

@@ -195,7 +200,7 @@ }

], function(_error) {
], function (_error) {
//Stream it back.
gmImage.stream(function(_error, _stdout, _stderr) {
if (_error) {
gmImage.stream(function (_error, _stdout, _stderr) {
if(_error) {
console.log(_error);

@@ -214,3 +219,3 @@ return _manipulationDoneCallback(_error);

//Close up the waterfall when done
_stdout.on('end', function() {
_stdout.on('end', function () {
_manipulationDoneCallback(null);

@@ -223,4 +228,4 @@ })

], function(_error) {
if (_error) {
], function (_error) {
if(_error) {
_next(_error);

@@ -227,0 +232,0 @@ }

@@ -16,5 +16,5 @@ var async = require('async'),

describe('immp', function() {
describe('immp', function () {
before(function(_done) {
before(function (_done) {
cluster.setupMaster({

@@ -24,3 +24,3 @@ exec: path.join(cwd, '/bin/www')

cluster.fork();
setTimeout(function() {
setTimeout(function () {
_done();

@@ -30,5 +30,5 @@ }, 300);

after(function() {
after(function () {
var immpFiles = fs.readdirSync(immpPath);
immpFiles.forEach(function(_file) {
immpFiles.forEach(function (_file) {
fs.unlinkSync(path.join(immpPath, '/', _file));

@@ -38,12 +38,12 @@ });

it('should resize by width', function(_done) {
it('should resize by width', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=200x0', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=200x0', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -59,12 +59,12 @@ _size.width.should.equal(200);

it('should resize by height', function(_done) {
it('should resize by height', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=0x200', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=0x200', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -80,12 +80,12 @@ _size.height.should.equal(200);

it('should not upscale by default', function(_done) {
it('should not upscale by default', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=2000x2000', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=2000x2000', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -102,12 +102,12 @@ _size.width.should.equal(1920);

it('should upscale when upscaling is true', function(_done) {
it('should upscale when upscaling is true', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=2000x2000&upscale=true', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=2000x2000&upscale=true', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -124,12 +124,12 @@ _size.width.should.equal(2000);

it('should resize by width and height and retain the aspect ratio', function(_done) {
it('should resize by width and height and retain the aspect ratio', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=100x200', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&resize=100x200', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -142,3 +142,3 @@ _size.width.should.equal(100);

}).on('error', function(_error) {
}).on('error', function (_error) {
_done(_error);

@@ -149,12 +149,12 @@ });

it('should crop to a square', function(_done) {
it('should crop to a square', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=1x1', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=1x1', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -171,12 +171,12 @@ _size.width.should.equal(1080);

it('should crop to a short width big height ratio', function(_done) {
it('should crop to a short width big height ratio', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=9x16', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=9x16', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -194,12 +194,12 @@ _size.width.should.equal(608);

it('should crop to a big width short height ratio', function(_done) {
it('should crop to a big width short height ratio', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=16x9', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=16x9', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -216,12 +216,12 @@ _size.width.should.equal(1920);

it('should crop and resize', function(_done) {
it('should crop and resize', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=1x1&resize=50x100', function(_httpResponse) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function(_error, _size) {
if (_error) return _done(_error);
.size(function (_error, _size) {
if(_error) return _done(_error);

@@ -238,3 +238,3 @@ _size.width.should.equal(50);

it('should set the quality', function(_done) {
it('should set the quality', function (_done) {
this.slow(5000);

@@ -246,10 +246,10 @@ this.timeout(10000);

// Get the size without compression
function(_callback) {
function (_callback) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&quality=invalidQualityValue', function(_httpResponse) {
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);
.filesize(function (_error, _filesize) {
if(_error) return _callback(_error);
_callback(null, parseInt(_filesize));

@@ -263,10 +263,10 @@ });

// Get the size with compression
function(_fileSizeWithoutCompression, _callback) {
function (_fileSizeWithoutCompression, _callback) {
http.get('http://localhost:3000/im/?image=/images/robot.jpg&quality=50', function(_httpResponse) {
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);
.filesize(function (_error, _filesize) {
if(_error) return _callback(_error);
var filesize = parseInt(_filesize);

@@ -282,3 +282,3 @@ filesize.should.be.lessThan(_fileSizeWithoutCompression);

], function(_error) {
], function (_error) {
_done(_error);

@@ -289,2 +289,44 @@ });

it('should work for http images', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=http://localhost:3000/images/robot.jpg&crop=1x1&resize=50x100', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function (_error, _size) {
if(_error) return _done(_error);
_size.width.should.equal(50);
_size.height.should.equal(50);
_done();
});
});
});
it('should work for https images', function (_done) {
this.slow(5000);
this.timeout(10000);
http.get('http://localhost:3000/im/?image=https://www.google.com/images/srpr/logo11w.png&crop=1x1&resize=50x100', function (_httpResponse) {
gm(_httpResponse)
.options(gmOptions)
.size(function (_error, _size) {
if(_error) return _done(_error);
_size.width.should.equal(50);
_size.height.should.equal(50);
_done();
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc