def fromarray(obj, mode=None):
 arr = obj.__array_interface__
 shape = arr['shape']
 ndim = len(shape)
 try:
  strides = arr['strides']
 except KeyError:
  strides = None
 if (mode is None):
  try:
   typekey = (((1, 1) + shape[2:]), arr['typestr'])
   (mode, rawmode) = _fromarray_typemap[typekey]
  except KeyError:
   raise TypeError('Cannot handle this data type')
 else:
  rawmode = mode
 if (mode in ['1', 'L', 'I', 'P', 'F']):
  ndmax = 2
 elif (mode == 'RGB'):
  ndmax = 3
 else:
  ndmax = 4
 if (ndim > ndmax):
  raise ValueError(('Too many dimensions: %d > %d.' % (ndim, ndmax)))
 size = (shape[1], shape[0])
 if (strides is not None):
  if hasattr(obj, 'tobytes'):
   obj = obj.tobytes()
  else:
   obj = obj.tostring()
 return frombuffer(mode, size, obj, 'raw', rawmode, 0, 1)

def fromarray ( obj , mode = None ) : arr = obj . __array_interface__ shape = arr [ 'shape' ] ndim = len ( shape ) try : strides = arr [ 'strides' ] except KeyError : strides = None if ( mode is None ) : try : typekey = ( ( ( 1 , 1 ) + shape [ 2 : ] ) , arr [ 'typestr' ] ) ( mode , rawmode ) = _fromarray_typemap [ typekey ] except KeyError : raise TypeError ( 'Cannot handle this data type' ) else : rawmode = mode if ( mode in [ '1' , 'L' , 'I' , 'P' , 'F' ] ) : ndmax = 2 elif ( mode == 'RGB' ) : ndmax = 3 else : ndmax = 4 if ( ndim > ndmax ) : raise ValueError ( ( 'Too many dimensions: %d > %d.' % ( ndim , ndmax ) ) ) size = ( shape [ 1 ] , shape [ 0 ] ) if ( strides is not None ) : if hasattr ( obj , 'tobytes' ) : obj = obj . tobytes ( ) else : obj = obj . tostring ( ) return frombuffer ( mode , size , obj , 'raw' , rawmode , 0 , 1 )
creates an image memory from an object exporting the array interface .