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.
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) {
if (err) return;
if (self.position.width == null) {
self.position.width = size.width / tw | 0;
}
if (self.position.height == null) {
self.position.height = size.height / th | 0;
}
self.position.width = size.width / tw | 0;
self.position.height = size.height / th | 0;
});
}

View File

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