forked from danschumann/limby-resize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimby-resize.js
47 lines (33 loc) · 1.34 KB
/
limby-resize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* MIT License
* You may use this code as long as you retain this notice. Use at your own risk! :)
* https://github.com/danschumann/limby-resize
*/
(function(){
var _ = require('underscore');
var debug = require('debug')('limbyResizer');
var LimbyResizer;
LimbyResizer = function(config) {
if (!(this instanceof LimbyResizer)) return new LimbyResizer(config);
debug('constructor');
// Disable if they didn't configure a image resizing module to use
if (!config.imagemagick && !config.canvas)
throw new Error("You must initialize limby-resizer with config.(canvas|imagemagick) = require('canvas|imagemagick')");
this.config = config;
if (config.imagemagick)
require('./lib/imagemagick')(this);
else
require('./lib/canvas')(this);
};
LimbyResizer.prototype.resize = function(filePath, options){
var width, height;
width = options && options.width || this.config.width;
height = options && options.height || this.config.height;
if (width && !height)
throw new Error('If you specify width, you must also specify height');
if (!width && height)
throw new Error('If you specify height, you must also specify width');
return this._resize(filePath, _.extend(_.clone(options), {width: width, height: height}));
};
module.exports = LimbyResizer;
})();