Skip to content

Commit

Permalink
Implemented image resizing if image won't fit in window
Browse files Browse the repository at this point in the history
  • Loading branch information
bogwonch committed Aug 4, 2015
1 parent 9b48127 commit 992c526
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rainbowstream/c_image.py
Expand Up @@ -71,6 +71,17 @@ def image_to_display(path, start=None, length=None):
i.load()
width = min(w, length)
height = int(float(h) * (float(width) / float(w)))

if c['IMAGE_RESIZE_TO_FIT'] is True:
# If it image won't fit in the terminal without scrolling shrink it
# Subtract 3 from rows so the tweet message fits in too.
h = 2 * (int(rows) - 3)
if height >= h:
width = int(float(width) * (float(h) / float(height)))
height = h
if (height <= 0) or (width <= 0):
raise ValueError("image has negative dimensions")

i = i.resize((width, height), Image.ANTIALIAS)
height = min(height, c['IMAGE_MAX_HEIGHT'])

Expand Down
2 changes: 2 additions & 0 deletions rainbowstream/rainbow.py
Expand Up @@ -242,6 +242,8 @@ def init(args):
set_config('IMAGE_ON_TERM', str(c['IMAGE_ON_TERM']))
# Use 24 bit color
c['24BIT'] = args.color_24bit
# Resize images based on the current terminal size
set_config('IMAGE_RESIZE_TO_FIT', str(c.get('IMAGE_RESIZE_TO_FIT', False)))
# Check type of ONLY_LIST and IGNORE_LIST
if not isinstance(c['ONLY_LIST'], list):
printNicely(red('ONLY_LIST is not a valid list value.'))
Expand Down

0 comments on commit 992c526

Please sign in to comment.