0

I am trying to create an image upload utility in Hug / python and wanted to save images and gifs. But on uploading some of the gif images, the gif images seem to be a lot pixelated. Given below is the code snippet that I am using in the upload utility.

 image = Image.open(io.BytesIO(file))
 frames = [frame.copy() for frame in ImageSequence.Iterator(image)]
 image.save(media_location, save_all=True, append_images=frames)
  • The original GIF :

    via GIPHY


    enter image description here


    The uploaded GIF

    enter image description here
Pradhvan Bisht
  • 341
  • 2
  • 5
  • 13

1 Answers1

0

Fixed it!

The workaround can be not passing the animated images with PIL and directly storing it with a context manager.

    if image.is_animated:
        with open(media_location, 'wb') as fp:
            fp.write(byte_stream)
Pradhvan Bisht
  • 341
  • 2
  • 5
  • 13