code: def test_animated_gif(setup_library, tmp_path):
      fnamebase = str(tmp_path / "test")
  
      # Get images
      im = get_ref_im(4, 0, 0)
      ims = []
      for i in range(10):
          im = im.copy()
          im[:, -5:, 0] = i * 20
          ims.append(im)
  
      # Store - animated GIF always poops out RGB
      for isfloat in (False, True):
          for colors in (3, 4):
              ims1 = ims[:]
              if isfloat:
                  ims1 = [x.astype(np.float32) / 256 for x in ims1]
              ims1 = [x[:, :, :colors] for x in ims1]
              fname = fnamebase + ".animated.%i.gif" % colors
              iio.mimsave(fname, ims1, duration=0.2, format="GIF-FI")
              # Retrieve
              ims2 = iio.mimread(fname, format="GIF-FI")
              ims1 = [x[:, :, :3] for x in ims]  # fresh ref
              ims2 = [x[:, :, :3] for x in ims2]  # discart alpha
              for im1, im2 in zip(ims1, ims2):
                  assert_close(im1, im2, 1.1)
  
      # We can also store grayscale
      fname = fnamebase + ".animated.%i.gif" % 1
      iio.mimsave(
          fname,
          [x[:, :, 0] for x in ims],
          duration=0.2,
          format="GIF-FI",
      )
      iio.mimsave(
          fname,
          [x[:, :, :1] for x in ims],
          duration=0.2,
          format="GIF-FI",
      )
  
      # Irragular duration. You probably want to check this manually (I did)
      duration = [0.1 for i in ims]
      for i in [2, 5, 7]:
          duration[i] = 0.5
      iio.mimsave(
          fnamebase + ".animated_irr.gif",
          ims,
          duration=duration,
          format="GIF-FI",
      )
  
      # Other parameters
      iio.mimsave(
          fnamebase + ".animated.loop2.gif",
          ims,
          loop=2,
          fps=20,
          format="GIF-FI",
      )
      R = iio.read(fnamebase + ".animated.loop2.gif", format="GIF-FI")
      W = iio.save(
          fnamebase + ".animated.palettes100.gif",
          palettesize=100,
          format="GIF-FI",
      )
      assert W._palettesize == 128
      # Fail
      raises(IndexError, R.get_meta_data, -1)
      raises(
          ValueError,
          iio.mimsave,
          fname,
          ims,
          quantizer="foo",
          format="GIF-FI",
      )
      raises(
          ValueError,
          iio.mimsave,
          fname,
          ims,
          duration="foo",
          format="GIF-FI",
      )
  
      # Add one duplicate image to ims to touch subractangle with not change
      ims.append(ims[-1])
  
      # Test subrectangles
      iio.mimsave(
          fnamebase + ".subno.gif",
          ims,
          subrectangles=False,
          format="GIF-FI",
      )
      iio.mimsave(
          fnamebase + ".subyes.gif",
          ims,
          subrectangles=True,
          format="GIF-FI",
      )
      s1 = os.stat(fnamebase + ".subno.gif").st_size
      s2 = os.stat(fnamebase + ".subyes.gif").st_size
      assert s2 < s1
  
      # Meta (dummy, because always {}
      assert isinstance(iio.read(fname).get_meta_data(), dict)
  
imports: import os
  import shutil
  import sys
  import platform
  import warnings
  import fsspec
  import imageio.plugins
  import imageio.v3
  import imageio.v2
  import numpy
  import pytest
  from imageio import core
  from imageio.core import IS_PYPY
  from pytest import raises
  from conftest import deprecated_test
label_desc: Use image node_id 16 for calling a global function with example usage: test_animated_gif(setup_library, tmp_path) without return types