1

Looking for an easy way (i.e. short code + minimum library dependency) to convert a 4D numpy array (Time x Width x Height x Channel) into a gif file (i.e. getting a BytesIO) without saving it on disk.

All the libraries that I looked at (e.g. moviepy and PIL) save the frames on disk only and their API does not allow for a custom Stream. I have a diskless setup and need to get the bytes without saving them.

MBZ
  • 26,084
  • 47
  • 114
  • 191
  • Technically speaking, you want a GIF-encoded image, not a GIF file. – DYZ Aug 04 '18 at 00:33
  • This may help: [Python PIL: how to write PNG image to string](https://stackoverflow.com/questions/646286/python-pil-how-to-write-png-image-to-string) – DYZ Aug 04 '18 at 00:39
  • @DYZ thanks. it seems that `Animation.save` is different from `Image.save`. Former does not accept a file pointer and only works with a file name. – MBZ Aug 04 '18 at 00:41
  • [One more possibly useful question](https://stackoverflow.com/questions/33916409/python-pil-save-image-in-memory-and-upload) – DYZ Aug 04 '18 at 00:44

0 Answers0