def save_thumbnail(image, thumb_path, shape):
 rescale = min(((float(w_1) / w_2) for (w_1, w_2) in zip(shape, image.shape)))
 small_shape = (rescale * np.asarray(image.shape[:2])).astype(int)
 small_image = transform.resize(image, small_shape)
 if (len(image.shape) == 3):
  shape = (shape + (image.shape[2],))
 background_value = dtype_range[small_image.dtype.type][1]
 thumb = (background_value * np.ones(shape, dtype=small_image.dtype))
 i = ((shape[0] - small_shape[0]) // 2)
 j = ((shape[1] - small_shape[1]) // 2)
 thumb[i:(i + small_shape[0]), j:(j + small_shape[1])] = small_image
 io.imsave(thumb_path, thumb)

def save_thumbnail ( image , thumb_path , shape ) : rescale = min ( ( ( float ( w_1 ) / w_2 ) for ( w_1 , w_2 ) in zip ( shape , image . shape ) ) ) small_shape = ( rescale * np . asarray ( image . shape [ : 2 ] ) ) . astype ( int ) small_image = transform . resize ( image , small_shape ) if ( len ( image . shape ) == 3 ) : shape = ( shape + ( image . shape [ 2 ] , ) ) background_value = dtype_range [ small_image . dtype . type ] [ 1 ] thumb = ( background_value * np . ones ( shape , dtype = small_image . dtype ) ) i = ( ( shape [ 0 ] - small_shape [ 0 ] ) // 2 ) j = ( ( shape [ 1 ] - small_shape [ 1 ] ) // 2 ) thumb [ i : ( i + small_shape [ 0 ] ) , j : ( j + small_shape [ 1 ] ) ] = small_image io . imsave ( thumb_path , thumb )
save image as a thumbnail with the specified shape .