python处理并压缩图片
时间: 2023-10-18 19:05:28 浏览: 93
要处理和压缩图像,可以使用Python中的Pillow库。以下是一个示例代码,演示如何打开图像,调整大小,应用滤镜并保存压缩后的图像:
```python
from PIL import Image
# 打开图像
img = Image.open('example.jpg')
# 调整大小
img = img.resize((800, 800))
# 应用滤镜
img = img.filter(ImageFilter.BLUR)
# 保存压缩后的图像
img.save('example_compressed.jpg', optimize=True, quality=50)
```
在这个例子中,我们首先打开名为“example.jpg”的图像。然后,我们将其大小调整为800x800像素,并应用了一个模糊滤镜。最后,我们使用“optimize”和“quality”参数将压缩质量设置为50,并将结果保存为名为“example_compressed.jpg”的文件。
阅读全文
相关推荐
















