I am using Pillow 9.1.0 to flip an image upside-down.
from PIL import Image
img = Image.open('example.png')
flipped = img.transpose(Image.FLIP_TOP_BOTTOM)
Recently a warning shown up:
DeprecationWarning: FLIP_TOP_BOTTOM is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_TOP_BOTTOM instead.
flipped = img.transpose(Image.FLIP_TOP_BOTTOM)
I tried to import Transpose from PIL but it did not work.
from PIL import Image, Transpose
Traceback (most recent call last):
File "example.py", line 1, in <module>
from PIL import Image, Transpose
ImportError: cannot import name 'Transpose' from 'PIL' (.../site-packages/PIL/__init__.py)
How to import and use Transpose.FLIP_TOP_BOTTOM properly?
It's all written in the deprecation document. Instead of Image.FLIP_TOP_BOTTOM, you should be using Image.Transpose.FLIP_TOP_BOTTOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With