在Python中,使用Pillow库可以很容易地实现图像旋转。以下是一个具体的程序示例:
安装Pillow库
```bash
pip install pillow
```
旋转图像的代码
```python
from PIL import Image
打开要处理的图像
image = Image.open('your_image.jpg')
旋转图像90度
rotated_image = image.rotate(90)
保存旋转后的图像
rotated_image.save('rotated_image.jpg')
```
在这个示例中,我们首先导入了Pillow库中的Image模块,然后打开了一个名为`your_image.jpg`的图像文件。接着,我们使用`rotate()`方法将图像旋转了90度,并将旋转后的图像保存为`rotated_image.jpg`。
如果你想要旋转其他角度,只需将`rotate()`方法中的参数更改为所需的角度即可。例如,旋转45度:
```python
rotated_image = image.rotate(45)
```
此外,你还可以通过指定旋转中心来旋转图像。例如,将图像绕其中心点旋转45度:
```python
rotated_image = image.rotate(45, center=(image.width / 2, image.height / 2))
```
希望这个示例程序对你有所帮助!如果有任何问题或需要进一步的说明,请随时告诉我。