扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Pillow怎么将图像转换为不同的格式

扬州沐宇科技
2024-05-22 17:03:06
pillow

你可以使用Python中的Pillow库来将图像转换为不同的格式。以下是一个简单的示例代码,将图像转换为不同的格式:

from PIL import Image

# 打开图像
image = Image.open('example.jpg')

# 将图像保存为PNG格式
image.save('example.png')

# 将图像保存为JPEG格式
image.save('example.jpg')

# 将图像保存为BMP格式
image.save('example.bmp')

# 将图像保存为GIF格式
image.save('example.gif')

在这个示例中,我们首先使用Image.open()方法打开一个图像文件,然后使用save()方法将图像保存为不同的格式。你可以根据你的需要修改文件名和保存的格式。

扫码添加客服微信