def encode_thumbnail(thumbnail):
 from calibre.utils.imghdr import identify
 if (thumbnail is None):
  return None
 if (not isinstance(thumbnail, (tuple, list))):
  try:
   (width, height) = identify(bytes(thumbnail))[1:]
   if ((width < 0) or (height < 0)):
    return None
   thumbnail = (width, height, thumbnail)
  except Exception:
   return None
 return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))

def encode_thumbnail ( thumbnail ) : from calibre . utils . imghdr import identify if ( thumbnail is None ) : return None if ( not isinstance ( thumbnail , ( tuple , list ) ) ) : try : ( width , height ) = identify ( bytes ( thumbnail ) ) [ 1 : ] if ( ( width < 0 ) or ( height < 0 ) ) : return None thumbnail = ( width , height , thumbnail ) except Exception : return None return ( thumbnail [ 0 ] , thumbnail [ 1 ] , b64encode ( str ( thumbnail [ 2 ] ) ) )
encode the image part of a thumbnail .