0

Im trying to make a script that takes and input image and fades it out. So far this is my script

imgObject = im.open(imageName)
toAppend = []

for i in range(int(256)):
    imgObject.putalpha(i)
    toAppend.append(imgObject)
    #imgObject.save('images/'+str(i)+'.png', 'PNG')

imgObject.save('finished.gif', save_all=True, append_images=toAppend)

When this is run, the output gif is just a still of the input with no changes. But if i save each image as a png, then the transparency works! It saves 255 different images where you can see it fade out. I've also tried stitching these photos together after the fact, but the same or similar problems occurred. I've also tried this, this, this, and this. All producing the same effect.

PersonMon
  • 33
  • 1
  • 3
  • You can't have "smooth transparencies" with GIF, pixels can be either fully transparent or opaque, cf. [this Q&A](https://stackoverflow.com/a/66453943/11089932). – HansHirse Apr 12 '21 at 06:56
  • Well my final goal is to have it fade INTO another image, so would it work if the image below it is at full opacity? If so, how would you go about layering 2 images on top of each other? – PersonMon Apr 12 '21 at 14:12

1 Answers1

0

Read more into the docs and found this

imgObject = im.open(imageName)
bpiObject = im.open(backroundName)
toAppend = []

for i in range(100):
    imgObject = im.blend(imgObject, bpiObject, i/100)
    toAppend.append(imgObject)

imgObject.save('finished.gif', save_all=True, append_images=toAppend, loop = 0)

This worked for me, they do have to have the same dimensions though

PersonMon
  • 33
  • 1
  • 3