Is it possible to put an image from a URL into the terminal

时间:2017-12-18 04:53:45

标签: python image python-2.7

I have an image hosted at a specific url online and I would like that image to appear in the terminal when run. Is that possible or is there a way the image can be shown in a native image viewer?

1 个答案:

答案 0 :(得分:0)

You'll need some way of fetching and displaying the image. A web browser can do both of those things, so one way to do what you want is to start up a web browser and point it at the desired URL:

import webbrowser
webbrowser.open(url)

If the user already has a web browser open but it is not currently visible (i.e. it's minimized or it's on a different virtual desktop), it might work better to tell webbrowser to open the page in a new window, which would (presumably) be displayed on the current screen:

webbrowser.open_new(url)

However, this is not guaranteed to work (perhaps the browser is configured to always display new urls in a tab instead of a new window, etc etc.)