0

I'm trying to load image from the internet.

from PIL import Image

Image.open("https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg")

then this error below.

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-d6dfd73d2382> in <module>
      1 from PIL import Image
----> 2 Image.open("https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg")

~\anaconda3\lib\site-packages\PIL\Image.py in open(fp, mode, formats)
   2910 
   2911     if filename:
-> 2912         fp = builtins.open(filename, "rb")
   2913         exclusive_fp = True
   2914 

OSError: [Errno 22] Invalid argument: 'https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg'

I found out that files on my computer can be loaded by writing the path like c:/.../ . But writing the path like http://... returns error. How to load an image from the internet?

Imran
  • 381
  • 4
  • 15
JH LEE
  • 21
  • 2

1 Answers1

0

You can use this:

from PIL import Image
import requests
from io import BytesIO

response = requests.get(url)
img = Image.open(BytesIO(response.content))
Prophet
  • 32,350
  • 22
  • 54
  • 79