from PIL import Image
# 打开一个图像文件
img = Image.open("example.jpg")
# 显示图像
img.show()
# 获取图像的基本信息
print(f"图像格式: {img.format}")
print(f"图像尺寸: {img.size}")
print(f"图像模式: {img.mode}")
# 保存图像为其他格式
img.save("example.png")
# 创建一个新的白色背景的图像
new_img = Image.new('RGB', (500, 500), color = 'white')
# 裁剪图像
box = (100, 100, 400, 400) # 左上角和右下角坐标
cropped_img = img.crop(box)
# 翻转图像
flipped_img = img.transpose(Image.FLIP_LEFT_RIGHT)
# 旋转图像
rotated_img = img.rotate(45)
# 缩放图像
resized_img = img.resize((300, 300))
# 将图像转换为灰度图
gray_img = img.convert('L')
# 关闭图像文件
img.close()
上一篇:python self的作用
下一篇:python exec函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站