summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/default_config.cfg5
-rw-r--r--poezio/config.py1
-rw-r--r--poezio/windows/image.py25
3 files changed, 30 insertions, 1 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index a166cc46..985fb30d 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -436,6 +436,11 @@ use_bookmarks_method =
# Display your contacts’ avatar in the roster if true.
#enable_avatars = false
+# Use Unicode half-block (▄) instead of full-block (█) to display images.
+# This doubles the vertical resolution and gives square pixels, but may
+# cause issues in some terminals.
+#image_use_half_blocks = false
+
# Extract base64 images received in XHTML-IM messages
# if true.
#extract_inline_images = true
diff --git a/poezio/config.py b/poezio/config.py
index 528debc6..8077a9c6 100644
--- a/poezio/config.py
+++ b/poezio/config.py
@@ -76,6 +76,7 @@ DEFAULT_CONFIG = {
'highlight_on': '',
'ignore_certificate': False,
'ignore_private': False,
+ 'image_use_half_blocks': False,
'information_buffer_popup_on': 'error roster warning help info',
'information_buffer_type_filter': '',
'jid': '',
diff --git a/poezio/windows/image.py b/poezio/windows/image.py
index 09a11d6f..aa9d9c3d 100644
--- a/poezio/windows/image.py
+++ b/poezio/windows/image.py
@@ -14,6 +14,7 @@ except ImportError:
from poezio.windows.base_wins import Win
from poezio.theming import to_curses_attr
from poezio.xhtml import _parse_css_color
+from poezio.config import config
class ImageWin(Win):
@@ -24,6 +25,10 @@ class ImageWin(Win):
def __init__(self):
self._image = None
Win.__init__(self)
+ if config.get('image_use_half_blocks'):
+ self._display_avatar = self._display_avatar_half_blocks
+ else:
+ self._display_avatar = self._display_avatar_full_blocks
def resize(self, height: int, width: int, y: int, x: int):
self._resize(height, width, y, x)
@@ -61,7 +66,7 @@ class ImageWin(Win):
width = int(new_width)
return width, height
- def _display_avatar(self, width: int, height: int):
+ def _display_avatar_half_blocks(self, width: int, height: int):
original_height = height
original_width = width
size = self._compute_size(self._image.size, width, height)
@@ -81,3 +86,21 @@ class ImageWin(Win):
r, g, b = line2[x * 3:(x + 1) * 3]
bot_color = _parse_css_color('#%02x%02x%02x' % (r, g, b))
self.addstr('▄', to_curses_attr((bot_color, top_color)))
+
+ def _display_avatar_full_blocks(self, width: int, height: int):
+ original_height = height
+ original_width = width
+ width, height = self._compute_size(self._image.size, width, height)
+ height //= 2
+ size = width, height
+ image2 = self._image.resize(size, resample=Image.BILINEAR)
+ data = image2.tobytes()
+ start_y = (original_height - height) // 2
+ start_x = (original_width - width) // 2
+ for y in range(height):
+ line = data[y * width * 3:(y + 1) * width * 3]
+ self.move(start_y + y, start_x)
+ for x in range(0, width * 3, 3):
+ r, g, b = line[x:x + 3]
+ color = _parse_css_color('#%02x%02x%02x' % (r, g, b))
+ self.addstr('█', to_curses_attr((color, -1)))