from PIL import Image # Open the image file with Image.open("image.jpg") as im: # Convert the image to JPEG im.convert("RGB").save("image.jpg")