class_docstr: Class that for helping write the animated GIF file. This is based on
  code from images2gif.py (part of visvis). The version here is modified
  to allow streamed writing.
class_docstr_tok: ["Class","that","for","helping","write","the","animated","GIF","file",".","This","is","based","on","code","from","images2gif.py","(","part","of","visvis",")",".","The","version","here","is","modified","to","allow","streamed","writing","."]
docstr: Calculate the minimal rectangle that need updating. Returns
  a two-element tuple containing the cropped image and an x-y tuple.
  
  Calculating the subrectangles takes extra time, obviously. However,
  if the image sizes were reduced, the actual writing of the GIF
  goes faster. In some cases applying this method produces a GIF faster.
docstr_tok: ["Calculate","the","minimal","rectangle","that","need","updating",".","Returns","a","two-element","tuple","containing","the","cropped","image","and","an","x-y","tuple",".","Calculating","the","subrectangles","takes","extra","time",",","obviously",".","However",",","if","the","image","sizes","were","reduced",",","the","actual","writing","of","the","GIF","goes","faster",".","In","some","cases","applying","this","method","produces","a","GIF","faster","."]
code: def getSubRectangle(self, im):
      """Calculate the minimal rectangle that need updating. Returns
      a two-element tuple containing the cropped image and an x-y tuple.
  
      Calculating the subrectangles takes extra time, obviously. However,
      if the image sizes were reduced, the actual writing of the GIF
      goes faster. In some cases applying this method produces a GIF faster.
      """
  
      # Cannot do subrectangle for first image
      if self._count == 0:
          return im, (0, 0)
  
      prev = self._previous_image
  
      # Get difference, sum over colors
      diff = np.abs(im - prev)
      if diff.ndim == 3:
          diff = diff.sum(2)
      # Get begin and end for both dimensions
      X = np.argwhere(diff.sum(0))
      Y = np.argwhere(diff.sum(1))
      # Get rect coordinates
      if X.size and Y.size:
          x0, x1 = int(X[0]), int(X[-1] + 1)
          y0, y1 = int(Y[0]), int(Y[-1] + 1)
      else:  # No change ... make it minimal
          x0, x1 = 0, 2
          y0, y1 = 0, 2
  
      return im[y0:y1, x0:x1], (x0, y0)
  
file_path: imageio/imageio/plugins/pillowmulti.py
imports: import logging
  import numpy
  from .pillow_legacy import PillowFormat, image_as_uint, ndarray_to_pil
label_desc: Use image node_id 10 for calling the GifWriter obj's underlying member method code with example usage: obj.getSubRectangle(im) and returns: im,  x0,  y0, im,  int,  int