code: def open(cls, filename):
          
          if filename.endswith('.gz'):
              fp = gzip.open(filename, 'rb')
              try:
                  return cls(fp, filename, compression='gz')
              finally:
                  fp.close()
          elif filename.endswith('.bz2'):
              fp = bz2.BZ2File(filename, 'rb')
              try:
                  return cls(fp, filename, compression='bz2')
              finally:
                  fp.close()
          else:
              with open(filename, 'rb') as fp:
                  return cls(fp, filename)
docs: Read an image file from disk
  
          Parameters
          ----------
          filename : string
              Name of file to read as an image file.  This file may be gzip
              (``.gz``) or bzip2 (``.bz2``) compressed.