I'm trying to invert an image downloaded from telegram with PIL and then send it back:
import PIL, PIL.Image, PIL.ImageFont, PIL.ImageOps
from io import BytesIO
foto = msg["reply_to_message"]["photo"][0]["file_id"]
path = '/home/****/mysite/'+str(secrets.randbelow(10000))
bot.download_file(foto, path) #download the photo from telegram (it works)
img = PIL.Image.open(path).convert('RGBA')
img = PIL.ImageOps.invert(img)
final = BytesIO()
img.save(final, 'png')
final.seek(0)
bot.sendPhoto(chat_id, final) #send the photo in the telegram chat
But the exception handler sends me this message:
Not supported for this image mode.
What's the problem?