Skip to content

Instantly share code, notes, and snippets.

@eruffaldi
Created November 3, 2017 13:07
Show Gist options
  • Save eruffaldi/106364fd0785376bde09ccd86bbd849e to your computer and use it in GitHub Desktop.
Save eruffaldi/106364fd0785376bde09ccd86bbd849e to your computer and use it in GitHub Desktop.
Python inline image with iterm2
import base64
import sys
#https://www.iterm2.com/utilities/imgls
def encode_iterm2_image(data,height=None):
if height is None:
height = "auto"
else:
height = "%spx" % height
return ("\x1B]1337;File=loss.jpg;width=auto;height=%s;inline=1;size=%dpreserveAspectRatio=1:" % (height,len(data))) + base64.b64encode(data)
print encode_iterm2_image(open(sys.argv[1],"rb").read(),100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment