shrink Image element by image size.

This commit is contained in:
Christopher Jeffrey 2015-02-01 14:01:55 -08:00
parent c365c937e2
commit 5a4ddda37d
2 changed files with 8 additions and 9 deletions

View File

@ -6623,15 +6623,14 @@ Image.prototype.setImage = function(img, callback) {
}); });
// XXX Move below code to callback. // XXX Move below code to callback.
if (self.shrink) { if (self.shrink || self.options.autofit) {
delete self.shrink;
delete self.options.shrink;
self.options.autofit = true;
self.imageSize(img, function(err, size) { self.imageSize(img, function(err, size) {
if (err) return; if (err) return;
if (self.position.width == null) {
self.position.width = size.width / tw | 0; self.position.width = size.width / tw | 0;
}
if (self.position.height == null) {
self.position.height = size.height / th | 0; self.position.height = size.height / th | 0;
}
}); });
} }

View File

@ -10,8 +10,8 @@ var img = blessed.image({
parent: screen, parent: screen,
left: 'center', left: 'center',
top: 'center', top: 'center',
width: 20, width: 'shrink',
height: 20, height: 'shrink',
bg: 'green', bg: 'green',
file: process.argv[2] || __dirname + '/test-image.png' file: process.argv[2] || __dirname + '/test-image.png'
}); });