I’m very confused and looking more for an explanation, because I can’t seem to find it on the internet.
So I want to create a simple gif of an rectangle that rotates around its center in python. The rectangle consists of alternating black and white pixels.
Now If I do that with image libraries like pillow or opencv they always need to interpolate some pixels and they become grey. I attached an image where you can see this.
Now if I do the same thing in Microsoft powerpoint, it can do a rotation perfectly. Where is the difference?
That’s the code I’m using:
frames = []
for i in range(15):
angle = i * 15
rotated_img = img.rotate(angle, resample=Image.Resampling.NEAREST, expand=True)
# Create a new image with the grey background
frame = background.copy()
# Calculate the position to paste the rotated image
rotated_w, rotated_h = rotated_img.size
offset = ((background.size[0] - rotated_w) // 2, (background.size[1] - rotated_h) // 2)
frame.paste(rotated_img, offset, rotated_img)
I was expecting no interpolation.