Image 是 [[pillow]] 中处理图像的核心模块,它提供了打开、创建、编辑和保存图像的基本功能。
方法
open
打开图片文件,返回一个 Image 对象。
Image.open(file)
- file: 图片路径
示例
from PIL import Image
img = Image.open(io.BytesIO(req_img))
width, height = img.size # 获取宽高
new
创建一个新的 Image 对象。
Image.new(mode, size, color)
- mode: 图像模式,如 RGB、RGBA 等
- size: 图像大小,如 (100, 100)
- color: 图像颜色,如 (255, 255, 255)
示例
from PIL import Image
img = Image.new( mode="RGB", size=(100, 100), color=(255, 255, 255), )