I am rotating an image with the following python code:
from PIL import Image
img = Image.open('banana.jpg')
rotated = img.rotate(10)
rotated.save('banana-rotated.jpg')
This makes the following transformation:
As you can see, the background is black. This question asks how to fill the background with a specific color. However, I would like to fill the background with the color of the image. Because I need to rotate many images, I do not want to set the background to a fixed color.
Is there some way to extend the image at the edges, with a color extrapolated from the image? Ideally, this would also work if the image does not have a uniform background.