From 5a4ddda37d2e1f4f2f430b03119e0fd4bc5bdf51 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 1 Feb 2015 14:01:55 -0800 Subject: [PATCH] shrink Image element by image size. --- lib/widget.js | 13 ++++++------- test/widget-image.js | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index de91323..b02dacd 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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; }); } diff --git a/test/widget-image.js b/test/widget-image.js index ca44fbf..8836d8b 100644 --- a/test/widget-image.js +++ b/test/widget-image.js @@ -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' });