herb_line / image.py
Jarver3's picture
Create image.py
37dfbb1 verified
raw
history blame contribute delete
500 Bytes
import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
def image(url):
response = requests.get(url) # 下載圖片
if response.status_code == 200: # 檢查是否成功下載
img = Image.open(BytesIO(response.content)) # 讀取圖片內容
plt.imshow(img) # 使用 matplotlib 顯示圖片
plt.axis('off') # 不顯示坐標軸
plt.show()
img.save('downloaded_image.jpg') # 保存圖片
else:
print('Failed to download image')