Online Image To Array

Sat 17 May 2025

title: "Online Image to Array" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


from PIL import Image
import numpy as np
import urllib.request
image_path = 'https://multimedia.bbycastatic.ca/multimedia/products/500x500/107/10736/10736343.jpg'
with urllib.request.urlopen(image_path) as url:
    with open('temp.jpg', 'wb') as f:
        f.write(url.read())

img = Image.open('temp.jpg')
img

png

print(img)
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=500x500 at 0x113092358>
image_array = np.asarray(Image.open('temp.jpg'))
image_array.shape
(500, 500, 3)


Score: 5

Category: image-analysis