Skip to content

Commit

Permalink
Merge branch 'jerch-fix_2883'
Browse files Browse the repository at this point in the history
  • Loading branch information
toonn committed Aug 23, 2023
2 parents f6c80e3 + 59733ef commit 3541095
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ranger/ext/img_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def _generate_iterm2_input(self, path, max_cols, max_rows):
return ""
image_width = self._fit_width(
image_width, image_height, max_cols, max_rows)
content = self._encode_image_content(path)
content, byte_size = self._encode_image_content(path)
display_protocol = "\033"
close_protocol = "\a"
if os.environ["TERM"].startswith(("screen", "tmux")):
Expand All @@ -366,7 +366,7 @@ def _generate_iterm2_input(self, path, max_cols, max_rows):

text = "{0}]1337;File=inline=1;preserveAspectRatio=0;size={1};width={2}px:{3}{4}\n".format(
display_protocol,
str(len(content)),
str(byte_size),
str(int(image_width)),
content,
close_protocol)
Expand All @@ -384,7 +384,8 @@ def _fit_width(self, width, height, max_cols, max_rows):
def _encode_image_content(path):
"""Read and encode the contents of path"""
with open(path, 'rb') as fobj:
return base64.b64encode(fobj.read()).decode('utf-8')
content = fobj.read()
return base64.b64encode(content).decode('utf-8'), len(content)

@staticmethod
def imghdr_what(path):
Expand Down

0 comments on commit 3541095

Please sign in to comment.