Created
January 11, 2018 21:32
-
-
Save antorsae/e4ddd00efb627eed5d8e41d023ee8394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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