I've been experimenting with PIL/Pillow and I've hit a brick wall. I've been trying to take a GIF, split it up into frames, modify the colour depth for each frame, and then join the frames up into a GIF again.
Here is my code:
from PIL import Image
def gif_depth_change(pathToGIF, colourDepth):
originalGIF = Image.open(pathToGIF)
newGIF = originalGIF.convert("P", palette=Image.ADAPTIVE, colors=colourDepth)
newGIF.show()
The convert() method doesn't seem to work here, as it only shows a single PNG that doesn't have the colour depth given as an argument.
I also tried this:
def gif_depth_change(pathToGIF, colourDepth):
originalGIF = Image.open(pathToGIF)
newFrames = []
for frame in range(0, originalGIF.n_frames):
originalGIF.seek(frame)
x = originalGIF.convert("P", palette=Image.ADAPTIVE, colors=colourDepth)
newFrames.append(x)
newFrames[0].save('changed-depth-gif.gif', format='GIF', append_images=newFrames[1:], save_all=True)
When run, this code saves a GIF but doesn't modify it in any way (it gives me the same GIF). I also tried using convert() on originalGIF.seek(frame) but that returned None.