-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Example for using LWIP to contain an image in a canvas. | ||
*/ | ||
|
||
var path = require('path'), | ||
lwip = require('../'); | ||
|
||
lwip.open('lena.jpg', function(err, image) { | ||
if (err) return console.log(err); | ||
image.contain(400,700,'green',function(err, image){ | ||
image.writeFile('lena_contain.jpg', function(err){ | ||
if (err) return console.log(err); | ||
console.log('done'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
require('./lib/ImagePrototypeInit'); | ||
require('./lib/BatchPrototypeInit'); | ||
|
||
require('./lib/ImagePrototypeExtensions'); | ||
|
||
module.exports = require('./lib/obtain'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(function(undefined) { | ||
|
||
var Image = require('./Image'), | ||
decree = require('decree'), | ||
defs = require('./defs'); | ||
|
||
var judges = { | ||
contain: decree(defs.args.contain) | ||
}; | ||
|
||
Image.prototype.contain = function() { | ||
var that = this; | ||
judges.contain( | ||
arguments, | ||
function(width, height, color, inter, callback) { | ||
var s = Math.min(width / that.width(), height / that.height()); | ||
that.scale(s, s, inter, function(err){ | ||
if (err) return callback(err); | ||
var padX = (width - that.width()) / 2, | ||
padY = (height - that.height()) / 2; | ||
that.pad( | ||
Math.ceil(padX), | ||
Math.ceil(padY), | ||
Math.floor(padX), | ||
Math.floor(padY), | ||
color, | ||
callback | ||
); | ||
}); | ||
} | ||
); | ||
}; | ||
|
||
})(void 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters