Search code examples
pythonpython-imaging-librarygifanimated-gif

Python Pillow transparent gif isn't working


I am trying to make a gif of the following icon rotating :

Icon

To attempt to achieve this I am running the following code in Python using the Pillow library :

from PIL import Image, ImageDraw

images = []

icon = Image.open("cameraIcon.png")

for i in range(0, 360):
    images.append(icon.rotate(i))

images[0].save('loadingIcon.gif', format='GIF', save_all=True, append_images=images[1:], duration=40, loop=0, transparency=0)

However the output of this code does not match what I want, I get the following gif :

enter image description here

I don't know what is happening and would appreciate any help, thank you.


Solution

  • I am having trouble doing it with PIL too, so here is an ImageMagick solution to keep you going while I work on it...

    for ((i=0;i<360;i+=5)) ; do 
       magick camera.png -virtual-pixel transparent -distort SRT "41 41 $i" miff:-
    done | magick -background none -dispose background -delay 20 miff:- anim.gif
    

    enter image description here