Python獲取圖片的大小/尺寸
- 2020 年 1 月 12 日
- 筆記
1、pil獲取: (1)、安裝擴展 pip install Pillow (2)、程式碼 from PIL import Image file_path = 'C:/Users/admin/Pictures/scence/1.jpg' img = Image.open(file_path) imgSize = img.size #大小/尺寸 w = img.width #圖片的寬 h = img.height #圖片的高 f = img.format #影像格式 print(imgSize) print(w, h, f) 列印: (534, 300) 534 300 JPEG 2、opencv獲取 (1)、安裝擴展 pip install opencv-python (2)、程式碼 import cv2 file_path = 'C:/Users/admin/Pictures/scence/1.jpg' img = cv2.imread(file_path) #讀取圖片資訊 #sp = img.shape[0:2] #截取長寬啊 sp = img.shape #[高|寬|像素值由三種原色構成] print(sp) 列印: (300, 534, 3)