image.transpose(Image.FLIP_LEFT_RIGHT)
时间: 2023-11-25 17:04:27 浏览: 110
图片左右切换
5星 · 资源好评率100%
This code will flip an image horizontally (left to right) using the PIL (Python Imaging Library) module. The resulting image will be a new image object that is a mirror image of the original image.
Here is an example of how to use this code:
```python
from PIL import Image
# Open the image file
image = Image.open('my_image.jpg')
# Flip the image horizontally
flipped_image = image.transpose(Image.FLIP_LEFT_RIGHT)
# Save the flipped image to a new file
flipped_image.save('flipped_image.jpg')
```
In this example, the original image file is opened using the `Image.open()` method from the PIL module. The `transpose()` method is then called on the image object, passing in the constant `Image.FLIP_LEFT_RIGHT` to indicate that the image should be flipped horizontally. The resulting flipped image is then saved to a new file using the `save()` method.
阅读全文