Skip to content

Instantly share code, notes, and snippets.

@antorsae
Created January 11, 2018 21:32
Show Gist options
  • Select an option

  • Save antorsae/e4ddd00efb627eed5d8e41d023ee8394 to your computer and use it in GitHub Desktop.

Select an option

Save antorsae/e4ddd00efb627eed5d8e41d023ee8394 to your computer and use it in GitHub Desktop.
# if you have iterm2 for osx (www.iterm2.com) this is a like print(...) for images in the console
import base64
import cStringIO
import numpngw
import numpy as np
def show_image(a):
if a.dtype != np.uint8:
a = a.astype(np.uint8)
png_array = cStringIO.StringIO()
numpngw.write_png(png_array, a)
encoded_png_array = base64.b64encode(png_array.getvalue())
png_array.close()
image_seq = '\033]1337;File=[width=auto;height=auto;inline=1]:'+encoded_png_array+'\007'
print(image_seq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment