-2

How do I print an image from a link in console?

The image link is "https://cdn.discordapp.com/avatars/826439366439993354/c107a313dba5b75dd388c2fca5df68f9.png", I know I can print this using the pillow module if I download the .png, but how would I do this if it's not downloaded? Is there any way to do this without downloading the image, just printing it in the console?

container
  • 1
  • 3
  • 2
    What do you mean? You can't show an image without downloading it first. Either you download it, or a library you use will do it, but either way, it has to be downloaded first. So, what do you mean? You want a function that does it (download then print) for you? Or you want to save disk and download it in memory only? – chrslg Oct 13 '22 at 17:34
  • I want it to use that picture from a URL only once without downloading it? If that's impossible, how do I make it download the picture, print it and delete it? – container Oct 13 '22 at 17:35
  • You have to *download* the image, but you can avoid *saving* it to a file. – CrazyChucky Oct 13 '22 at 17:48
  • How would I do that? – container Oct 13 '22 at 17:49
  • Furkan's answer should work. – CrazyChucky Oct 13 '22 at 17:55

2 Answers2

1

You can use BytesIO

from PIL import Image
import requests
from io import BytesIO

url = "https://cdn-icons-png.flaticon.com/512/164/164372.png"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
display(img)
-1

Maybe this will help you get the image: How do I read image data from a URL in Python?

And this should help you display it: How to show PIL Image in ipython notebook

NicoFoth
  • 11
  • 2