Skip to main content

Write a (list of) NumPy array(s) to an (animated) GIF.

Project description

Animation of random pixels converging from two colors to one color. T = 0.7 T_c. T = 0.7 T_c Animation of random pixels converging less slowly to one color. T = 0.88 T_c. T = 0.88 T_c Animation of random pixels staying mostly random. T = 1.06 T_c. T = 1.06 T_c

Array2GIF provides a single top-level function, write_gif(), to write a 3-D NumPy array to a GIF, or a list of these arrays to an animated GIF. It works for me - just small animations of thermodynamics simulations - like the magnetization in the Ising model shown here.


Here is an example for a 2 pixel by 3 pixel animated GIF with two frames, switching 5 frames per second. All animations from this library will loop indefinitely.

import numpy as np
from array2gif import write_gif

dataset = [
        [[255, 0, 0], [255, 0, 0]],  # red intensities
        [[0, 255, 0], [0, 255, 0]],  # green intensities
        [[0, 0, 255], [0, 0, 255]]   # blue intensities
        [[0, 0, 255], [0, 0, 255]],
        [[0, 255, 0], [0, 255, 0]],
        [[255, 0, 0], [255, 0, 0]]
write_gif(dataset, 'rgbbgr.gif', fps=5)

# or for just a still GIF
write_gif(dataset[0], 'rgb.gif')



pip install array2gif


pip install git+

Release History

1.0.4 (2018-06-22)


  • Fixed issue where error was raised when non-integer dataset is used: instead now it is cast to uint8 and a warning is raised if there’s a difference between the two images.
  • Addressed issue where no error is raised when there are more colors than possible in a GIF (256 max). Although it is possible to have a separate palette for every single frame, this is not implemented right now, and the initial global palette is used for the entire animation.

1.0.3 (2018-06-02)


  • Did not bump version in documentation last times.

1.0.1 (2018-06-02)


  • Fixed issue where the width and height of an image are swapped. This is clear in image editors but was not obvious when viewed in Chrome.

1.0.0 (2018-05-23)


  • It is now possible to use PIL ordering of data (rows x cols x rgb) in addition to the original ordering (rgb x rows x cols).


  • Fixed issue where array2gif would raise ValueError when using a 4D NumPy array with perfectly valid data. Now it is possible to use either a list of 3D NumPy arrays, or a 4D NumPy array for animated gifs.

0.1.0 (2016-09-30)

Initial release

  • One single function, write_gif.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for array2gif, version 1.0.4
Filename, size File type Python version Upload date Hashes
Filename, size array2gif-1.0.4-py2-none-any.whl (7.8 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size array2gif-1.0.4-py3-none-any.whl (7.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size array2gif-1.0.4.tar.gz (8.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page